I'm using the select function with jq to parse for items in a list that contain a certain value. I want the resulting output to be a json list, but jq gives me the objects individually:
Example:
$ a='{
"FOO": {
"name": "Donald",
"location": "Stockholm"
},
"BAR": {
"name": "Walt",
"location": "Stockholm"
},
"BAZ": {
"name": "Jack",
"location": "Whereever"
}
}'
$ echo $a | jq '.[] | select(.location=="Stockholm")'
{
"name": "Donald",
"location": "Stockholm"
}
{
"name": "Walt",
"location": "Stockholm"
}
Instead I want the output to be a json list like this:
[
{
"name": "Donald",
"location": "Stockholm"
},
{
"name": "Walt",
"location": "Stockholm"
}
]
How can I do this with jq?