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.
563 questions
1
vote
2
answers
85
views
How to pretty print one column of piped input?
bash 4.4.20 and jq-1.6 on RHEL8
I get this nice output from jq and column. Hard to read, though.
pgbackrest info --output=json \
| jq -r '.[] | .backup[] | "\(.type) \(.label) \(.info.delta)...
0
votes
0
answers
66
views
libvirt: "Error starting domain: internal error: failed to parse JSON: nesting too deep"
I'm on Fedora Linux 42.20250824.0 (Sway Atomic), running libvirt version 11.0.0, qemu-img version 9.2.4 (qemu-9.2.4-1.fc42) and virt-manager version 5.0.0, all installed as layered packages.
Using ...
0
votes
2
answers
221
views
Extracting two (or more) related values from an array of JSON objects
Consider a contrived example using a JSON object such as this, where I want to extract the related id, firstname, and lastname fields for each of many array objects into shell variables for further (...
2
votes
1
answer
89
views
Append to matching children of an arbitrarily deep array
I am attempting to edit an OpenAPI specification by changing all parameters to be nullable. A parameter definition looks like this:
{
"name": "foo",
"required": ...
8
votes
3
answers
1k
views
How can I make jq assign values to environment variables in one command?
Say, I provide jq with the following JSON body as input:
{"person1": {"name": "foo"}, "person2": {"name": "bar"}}
Is it possible to have jq ...
5
votes
2
answers
410
views
Merging multiple JSON data blocks into a single entity
I'm using an API (from SyncroMSP) that returns paginated JSON data. I can obtain the number of pages, and I can obtain the data with a tool such as curl. Each chunk is valid JSON but it only contains ...
6
votes
2
answers
393
views
Update object inside array inside another JSON object
I have a huge JSON object with an array of objects inside it. I have to add key:value pair to a specific object in the array. For example, let the input object is:
{
"a": {
"b&...
3
votes
1
answer
338
views
use jq to pick a key out of a list of a list of objects and raw output with newline separation for outer array items
I want to output a specific key of list of a list of hashes as lines where each outer array item is separated by an empty line. To illustrate:
Input is:
[
[
{
"visible": true,
...
0
votes
1
answer
121
views
removing first and last character and empty spaces from a json file [closed]
I have given sets of different input files as shown sample below
cat out.txt
[
{
"regional_unit": "node",
"source_name": "1753250187_SPS",
"...
0
votes
3
answers
413
views
Convert json data to comma separated string
I have a json object that has an unknown number of variables, like this:
{
"var1": 123,
"var2": 456,
"var3": 789
}
How can I automatically convert it to form ...
1
vote
1
answer
79
views
json formating with jq for json nested objects
how do I get jq to take json like this:
{
"responseHeader":{
"status":0,
"QTime":1
},
"cluster":{
"collections":{
"...
3
votes
2
answers
2k
views
How to generate double quoted JSON string with escaped double quotes?
I sometimes need to write JSON strings containing a string value that is itself a JSON string. e.g. In the following JSON object:
echo '{"rec" : " {\"id\": 1, \"name\&...
3
votes
2
answers
2k
views
jq create object with property name from variable
$ n="foo"; echo "{}" | jq --arg n "$n" '. += { "$n": $n }'
{
"$n": "foo"
}
My reading of https://jqlang.github.io/jq/manual/#types-and-...
-2
votes
3
answers
166
views
Awk to pick up json values
I am trying to get the job status from the below json file.. but while using awk it is returning
{
"id": 10870,
"type": "job",
"url": "/api/v2/...
3
votes
2
answers
722
views
Emulate gron using jq
I recently discovered jq and gron.
For my use case, gron is sufficient, but I am a little worried by lack of development. There are some bugs that have not been addressed in an year, while I see that ...
0
votes
4
answers
157
views
How to replace pattern in last line
I'm trying to replace "}," by "}" from the last line of a file :
My /etc/firefox/policies/policies.json file like this because I added the certificate lines using a for loop :
$ ...
-1
votes
1
answer
238
views
bash loop with jq [closed]
How can I update a json file using jq in a loop as below ? json file need to have the .queryToken updated and .result array appended using json in curl response body
while true
do
curl -k --location ...
3
votes
2
answers
387
views
Pairing and structuring elements from a JSON array, with jq
[
{
"key": "@timestamp",
"value": "2024-08-21 03:02:57.871"
},
{
"key": "@message",
"value": "Aug 21, ...
1
vote
1
answer
310
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 ...
-2
votes
1
answer
513
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:
{
"...
-2
votes
2
answers
157
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"
},
{
"...
5
votes
2
answers
620
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 ...
7
votes
3
answers
2k
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:
#...
9
votes
1
answer
2k
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 ...
0
votes
2
answers
469
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 $...
4
votes
2
answers
3k
views
jq: Printing multiple values from multiple arrays at once
The default functionality of jq is to send each object from an array one at a time, though the join operator can merge those values. My problem is in trying to print all the values from multiple ...
6
votes
2
answers
2k
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 ...
7
votes
2
answers
2k
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 ...
1
vote
2
answers
871
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. ...
-1
votes
5
answers
182
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.
...
0
votes
5
answers
221
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": {
...
0
votes
1
answer
2k
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 ...
1
vote
1
answer
168
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": ....
-1
votes
1
answer
358
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 ...
1
vote
2
answers
954
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....
1
vote
3
answers
458
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....
1
vote
2
answers
337
views
Updating and removing values in JSON array based on matching with placeholder values
I search for an object with a specific property and then update another property.
Given this input:
[
{
"replacements": [
{
"newValue": "0",
&...
2
votes
1
answer
384
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}}&...
-1
votes
1
answer
75
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 ...
2
votes
4
answers
3k
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
...
1
vote
1
answer
2k
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"...
0
votes
3
answers
1k
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 .... ...
-2
votes
1
answer
74
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, ...
9
votes
3
answers
6k
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, ...
1
vote
1
answer
58
views
Convert csv out of json in new coloumn
The below is my json code
[
{
"kind": "user",
"version": "v2",
"metadata": {
"name": "person1"
},
"...
0
votes
2
answers
224
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",
&...
0
votes
2
answers
754
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' \
...
0
votes
1
answer
1k
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&...
0
votes
1
answer
63
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 ...
0
votes
1
answer
494
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 ...