Reputation: 35
I have a test.json file and I want to print:
prob1, 9
prob2, 10
prob3, 11
cat test.json | jq --raw-output '.[].abc'
return 9,10,11 but I am not sure how to print keys as well.
{
"prob1":{
"abc":9,
"abcd":2,
"Foo":3
},
"prob2":{
"abc":10,
"abcd":2,
"Foo":3
},
"prob3":{
"abc":11,
"abcd":2,
"Foo":3
}
}
Upvotes: 0
Views: 618
Reputation: 385546
Two approaches:
jq -r 'to_entries[] | "\( .key ): \( .value.abc )"'
Demo on jqplay
jq -r 'keys[] as $key | .[$key] | "\( $key ): \( .abc )"'
Demo on jqplay
Upvotes: 1
Reputation: 35
jq -r 'to_entries[] | "\(.key): \(.value.abc)"'
prob1: 9
prob2: 10
prob3: 11
Upvotes: 1