I have the following json data:
[
{"name":"JSON", "good":true},
{"name":"XML", "good":false},
{"name":"JSON", "good":false},
{"name":"HTML", "good":false},
{"name":"XML", "good":true},
{"name":"XML", "good":false}
]
by using :
jq '.[] | select(.name =="XML") | .good', result will be :
false
true
false
How can I make it like [false,true,false] as a record?
Just try wrap the whole expression within an array constructor, []
jq '[.[] | select(.name =="XML") | .good]'
[
false,
true,
false
]
Or in a same line using the --compact-output
flag
jq --compact-output '[.[] | select(.name =="XML") | .good ]'
[false,true,false]
In short: gather the results as an array, and use the -c option, eg
$ jq -c 'map( select(.name =="XML") | .good )'
Output:
[false,true,false]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.