Questions tagged [jq]
Questions about the command line JSON processing tool jq.
406 questions
1
vote
2
answers
79
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
551
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
88
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
992
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
184
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
391
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
383
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
305
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
74
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
712
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
847
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 ...
-1
votes
1
answer
223
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
372
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, ...