Questions tagged [jq]
Questions about the command line JSON processing tool jq.
408 questions
-1 votes
1 answer
28 views
jq - adding values to multiple arrays of objects with creating missing objects and without removing existing values in arrays
I need to add or update values in multiple arrays without removing existed array values. Also I need to create objects If they did not exist. somefile.json: { "messages": { "...
3 votes
2 answers
185 views
jq - combine JSON objects with their arrays without duplicating or removing existing
I'm trying to combine the arrays of two JSON files I need to achieve this by combining the arrays without removing existing values of arrays and without removing any object. Sorting output arrays ...
1 vote
2 answers
104 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)...
5 votes
2 answers
591 views
Is there an equivalent of python's enumerate in jq?
I want to get the value after a selected item in a list in jq. Something like this seems like it would work: jq '. as $list | select(.focused == true) | .id as $id | $list | select(????) One way of ...
2 votes
1 answer
103 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 ...
0 votes
1 answer
216 views
Why did I got jq: 1 compile error?
I tried this script to see kubernetes volumes usage k get pods -n elk | jq -s '[flatten | .[].pods[].volume[]? | select(has("pvcRef")) ''{name: .pvcRef.name, capacityBytes, usedBytes, ...
5 votes
2 answers
433 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
412 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
354 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, ...
1 vote
1 answer
2k views
jq select multiple elements from an array
I have a JSON which looks like: { "type": "server-firmwareinventory-list-1", "members": [ { "type": "sever-hardware-firmware-1", &...
1 vote
1 answer
88 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
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-...
3 votes
2 answers
736 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 ...
11 votes
3 answers
886 views
jq - ip addr show in tabular format
I'd like to pretty print the ip addresses and show the output in in tabular format, including all the meta data such as valid_lft, temporary, etc. I figured out that ip -j addr show eth0 is giving me ...