Skip to main content

Questions tagged [json]

JSON (JavaScript Object Notation) is a lightweight data representation format that resembles JavaScript source and that is can be easily red by machines and edited by humans with some effort.

Filter by
Sorted by
Tagged with
2 votes
1 answer
159 views

Modify a key value with another one containing a path using slashes

I have a couple of hours (I started today) experience in Bash. I have been trying multiple times to modify the value from a key in a json file using it. I know that it's much easier in python but I ...
Diego Alejandro Gómez Pardo's user avatar
-2 votes
1 answer
100 views

How to replace a parameter's value in json file with a value taken from a different text file

I have a a large number of JSON files on a Linux machine, where I need to change the value of a parameter with value taken from a different text file. E.g.: If the JSON file has values like: { "...
vishal's user avatar
  • 97
-2 votes
2 answers
65 views

bash script replace credentials in json file

I have json file like this: { "sdpSemantics": "unified-plan", "iceServers": [ { "urls": "stun:1.1.1.1:3478" }, { "...
user613400's user avatar
5 votes
2 answers
255 views

Using jq to copy field from one object to a later object in a JSON array

I have a series of events represented in a JSON array. I want to move data in the fields of earlier events to a later event. Is there a way to do this with jq? Here is an example of what I'm looking ...
ralmond's user avatar
  • 51
7 votes
3 answers
1k views

Do I have a cleaner way to assign a parametrized json string to a bash variable?

I'd like to prepare a test for a REST petstore server by the mean of curl. To test its add new pet api, I prepare a json string that holds the Pet to insert in a bash function that executes the curl: #...
Marc Le Bihan's user avatar
8 votes
1 answer
407 views

How to use jq to get a value from two possible paths?

I wanted to use jq to get a specific value b from two possible paths (and these two only). So, basically, I wanted to say jq '(path1 OR path2) | .b' which should work if b is at one of the two paths ...
tinlyx's user avatar
  • 834
0 votes
2 answers
57 views

Issue with double quotes inside double quotes in JSON

I have a shell script part of which is the following JSON: curl --request POST \ --url 'https://'$jira_instance'.atlassian.net/rest/api/2/field/'$field_ID'/context/'$context_ID'/option' \ --user $...
dlyk1988's user avatar
  • 103
4 votes
2 answers
129 views

sort all arrays in a JSON file depth-first to get a consistent order

I'm tracking the configuration of some system in JSON format in a revision control system. Unfortunately that configuration is retrieved using some closed-source proprietary command, and the output ...
Stéphane Chazelas's user avatar
6 votes
2 answers
997 views

JQ returns json lines without commas

To be clear - I want a pseudo-JSON output that will be written into another static JSON file here... so not wrapped in an array or anything, simply getting the missing commas after each entity in my ...
Seer's user avatar
  • 165
1 vote
2 answers
127 views

pipe or redirect output from curl to ssh command

I'm pretty sure this isn't possible, but I have been wrong in the past. Basically, what I'd like to do is take the JSON output from a curl command and pipe it to jq for prettiness. Which works fine. ...
supradave's user avatar
-1 votes
5 answers
123 views

How to check the contents of an entire file against the pattern \s*{\s*}\s*?

How to check the contents of an entire file for compliance with the pattern \s*{\s*}\s* using busybox? You need to check the entire file from beginning to end, and not individual lines, as grep does. ...
Maxim's user avatar
  • 119
0 votes
5 answers
160 views

How to add content to a file before the last } character using Busybox utilities?

There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { ...
Maxim's user avatar
  • 119
0 votes
1 answer
466 views

If I have a json string how do I calculate the number of bytes needed when stored?

I have a json string formatted displayed in a web page. What I am trying to understand is what is the size in terms of bytes that this json string requires. If I copy and pipe to wc -c I get 1000 ...
Jim's user avatar
  • 1,421
1 vote
1 answer
58 views

jq expression to merge

I have the below JSON document from the Junos REST API. I am trying to simplify the document down to just a select few items. How would I accomplish this? Expected JSON: [ { "status": ....
verideskstar's user avatar
-1 votes
1 answer
158 views

How to transform lscpu output to JSON format?

I've had to deal with case I need the JSON format data of lscpu output, but -J key hasn't supported. So I made simple command line script allows to transform plain output to JSON which I'll post here ...
Aleksey's user avatar
  • 25
0 votes
2 answers
267 views

bash var substitution inside json to use in curl

Team, I am unable to substitute values inside json(myjson) to use in curl command. any hint? JENKINS_USERNAME="svc-user" JENKINS_USER_TOKEN="xxxx" JENKINS_INSTANCE_FQDN="sham....
AhmFM's user avatar
  • 125
1 vote
3 answers
227 views

Convert table to json

I have a large table of data that I would like to convert to json and am not sure if a tool like jq, mlr, or similar would be able to perform such a task without having to resort to my poor awk skills....
jesse_b's user avatar
  • 37.6k
0 votes
1 answer
144 views

Search field and replace other in jq

I am trying to search for an object having a specific property and then update another property. Given this input: [ { "replacements": [ { "newValue": "0&...
Jazzschmidt's user avatar
2 votes
1 answer
207 views

How to pass a single value argument to a JSON file from a script without overriding the existing values?

I have the following JSON file named pool.json: { "AllocateActions": {}, "Available": true, "Description": "Pool for nodes in cluster - {{CLUSTER_NAME}}&...
aneeshdevcube's user avatar
-1 votes
1 answer
49 views

Returning lines from a JSON log file which contain IP and timestamps read from a CSV file?

so I'm new to Shell Scripting and could use some help. So in my CSV file, I want to see if IP and timestamp values exists in some way in the line entries of the JSON log file, and if so, return that ...
Linuxnoob's user avatar
2 votes
4 answers
2k views

Stuck at passing JSON as argument in bash

I know many have asked similar questions, but I can't make it work. I have a file called Dependencies: Accounts Aggregates Blog Configuration Contacts Contents DataTypes Forms Geo Globalization Media ...
Saeed Neamati's user avatar
1 vote
1 answer
1k views

Add/modify key/value in json object

I've asked a similar question in the past but I'm having a hard time adapting that solution to this problem. I have the following json array: $ jq <<<"$json" [ { "id"...
jesse_b's user avatar
  • 37.6k
0 votes
3 answers
572 views

Don't split at spaces in jq output

I used jq to convert an array of words into an argument for a java program. its like arguments=$(jq '.nameField | "-i " + "\"" + . + "\""' file.json) java .... ...
decipher's user avatar
  • 312
-2 votes
1 answer
56 views

How to convert a CSV with paragraphs to JSON on macOS's BSD Terminal?

I have a huge text file that contains this structure: title;description;date The problem is that description main contain paragraphs, like: title;description;data MyText;Lorem ipsum dolor sit amet, ...
Duck's user avatar
  • 4,714
8 votes
3 answers
4k views

How to process JSON with strings containing invalid UTF-8

A large (and growing) number of utilities on Unix-like systems seem to be choosing the JSON format for data interchange¹, even though JSON strings cannot directly represent arbitrary file paths, ...
Stéphane Chazelas's user avatar
1 vote
1 answer
37 views

Convert csv out of json in new coloumn

The below is my json code [ { "kind": "user", "version": "v2", "metadata": { "name": "person1" }, "...
code userit's user avatar
0 votes
2 answers
57 views

Is it possible to read the very first value of the JSON response

Here is a JSON response I am receiving from a server: { "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32": { "entityId": "GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32", &...
Ashish's user avatar
  • 1
0 votes
2 answers
320 views

Getting Error "{"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]}

curl --request POST \ --url 'https://bankofloyal.atlassian.net/rest/api/2/issue' \ --user [email protected]:$JIRA_TOKEN \ --header 'Accept: application/json' \ ...
Abhishek Kumar's user avatar
0 votes
1 answer
593 views

How do I refer to attributes with dollar signs in the name in jq?

I have some JSON: { "Data": { "$id": "1", "voters": { "$id": "2", "$values": [ { "$id&...
Joel Breazeale's user avatar
0 votes
1 answer
36 views

Force Patch character differences to a file

Hello, I have an englishStrings.json file and when I make new edits/ additions to it, I need to copy the new changes to all the other language string.json files. Before making any changes to ...
Freezer Fridge's user avatar
0 votes
1 answer
310 views

Conditional JSON transformation using jq

I have a system that outputs multiple types of JSON files with data. Is there any chance to implement the three conditions below using jq? I am exploring the map() command, and the --arg and --argjson ...
infotechsups's user avatar
2 votes
2 answers
3k views

Convert json to csv with headers in jq

Is it possible to convert this json: [ { "bytes": 276697, "checked": false }, { "bytes": 276697, "checked": false ...
Daniel Krajnik's user avatar
0 votes
1 answer
133 views

Forcing miller to read data as string in conversion to JSON

In the following MWE echo x="1e2" | mlr --ojson cat my intention is for miller to generate a one-element JSON array containing the object {"x": "1e2"} The object ...
Marcos's user avatar
  • 103
8 votes
4 answers
2k views

How to format a JSON string as a table using jq?

I need to convert a JSON string using jq, as shown below, into a table format for displaying the output in the terminal. { "results": [ [ { "field": "@...
Velin Budinov's user avatar
0 votes
2 answers
439 views

Using jq to parse invalid JSON?

Can jq parse invalid JSON such as this?: [2023.06.07-21.58.47] StatManagerLog: { "RoundState": { "State": "Starting", "Timestamp": "...
swat37's user avatar
  • 3
0 votes
2 answers
344 views

Add new key to JSON file, with value equal to the length of other key's value

I'm adjusting a JSON file that holds a large number of objects. Here are the first three objects as an example: {"id":"0704.0001","submitter":"Pavel Nadolsky",&...
A.Co's user avatar
  • 3
0 votes
1 answer
231 views

Unable to resolve parameter inside json

I'm using a curl command inside a script (edm.ksh) to retrieve some data from an API, it requires a password in a JSON like {"password":"myPassword"}. Now, myPassword is not ...
Pratik Khobragade's user avatar
1 vote
1 answer
1k views

How to keep one specific key from a nested json object?

I have the following config.json file: { "auths": { "reg1.io": { "auth": "...
Franck's user avatar
  • 13
2 votes
2 answers
133 views

How can I select only successful values from leakcheck output?

I have these results that came from leakcheck. How do I properly exclude "false" results and still include the email using bash [email protected] {"success":false,"error":&...
noobwithskillissue's user avatar
7 votes
4 answers
2k views

How to gather values into array by keys?

Given input in entries format, possibly with duplicated keys, e.g. [ {"key": "a", "value": 0}, {"key": "a", "value": 1}, {"key&...
友人A's user avatar
  • 173
4 votes
4 answers
2k views

How can I edit this JSON file with bash script and jq

I have config.json file with the following content: [{ "host0": "11.11.11.11", "host1": "22.22.22.22", "host2": "33.33.33.33", "...
Trinitron's user avatar
1 vote
1 answer
4k views

How to send multiline data in curl body within bash script?

I am trying to send multi-line comment in the curl body from bash script. Below is my curl invocation. #!/bin/bash temp="This is sample data: 2019/05/21 03:33:04 This is 2nd sample data: #...
Preeti 's user avatar
  • 223
0 votes
3 answers
189 views

How to fetch the value inside a json file for linux

I have an data which i am trying to fetch various method and the result is [ "created:Alpha;DateCreated:12/12/2022;TicketNo:XXXX_XXX;ProductName:websphere;OStype:Linux" ] I want to fetch ...
raj krish's user avatar
0 votes
1 answer
846 views

Get parent of all matching value in JSON using jq

I am new to jq and I have a scenario to get the parent(at a particular level) of any matching value in the json file. Below is the sample data. { "DevOps": { "us-east-1"...
Murali SP's user avatar
0 votes
2 answers
4k views

Expand variable in the JSON payload of a curl command

I have a shell script that sends a post request with curl. #!/bin/sh NEXT_JOB_COMMANDS='["sleep", "200s"]' STATUS="successful" if [ "$STATUS" = "...
ar-siddiqui's user avatar
0 votes
3 answers
79 views

How to print the content between the third and the forth double quotation marks

I have some logs from a web service on a Linux machine. The logs look like this: {"log":"[2023-03-09T06:39:10.669Z] \"GET /server/prod?blank=true HTTP/1.1\" 200 - 0 874 1 1 \&...
Yves's user avatar
  • 3,331
6 votes
4 answers
3k views

Generating JSON in a shell script

I need to generate JSON output as below: [{ "Service": "service1-name", "AWS Account": "service1-dev", "AD Accounts": { "APP-...
Marco Ferrara's user avatar
6 votes
2 answers
6k views

How to add a key value pair into a JSON file with JQ?

I have the following JSON file located at /tmp/target.json: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", ... } } I want to add ...
CaTx's user avatar
  • 171
0 votes
2 answers
320 views

Extract value from broken JSON output in Shell

Once I list the backup files from a server, It throws me the output as follows: { "backupFiles": [ "XYZ_Backup_2.0.0.0-417_2022_08_14_12_10.gz", "...
user560884's user avatar
1 vote
2 answers
9k views

get key and value from json in array with check

I had a json [ { "name": "type1", "type": "string", "values": { "set1": "dataA1", ...
decipher's user avatar
  • 312

1
2 3 4 5
11