Say I have a file obj1.json like this:
{
"name": "chalk",
"id": 1
}
And another file obj2.json like this:
{
"name": "cheese",
"id": 0
}
How do I collect the objects into a list like this?
[
{
"id": 1,
"name": "chalk"
},
{
"id": 0,
"name": "cheese"
}
]
I tried to use jq's array constructor on the objects.
cat obj1.json obj2.json |
jq "[.]"
But it produces one list _per_ object instead of one list _of_ objects.
[
{
"id": 1,
"name": "chalk"
}
]
[
{
"id": 0,
"name": "cheese"
}
]
cat ... | jq -s .
Ah, I missed that in the manual.
--slurp/-s:Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once.
Thanks!
Most helpful comment