Say I have the input:
{ "name": "John", "email": "[email protected]" } { "name": "Brad", "email": "[email protected]" }
How do I get the output:
[ { "name": "John", "email": "[email protected]" }, { "name": "Brad", "email": "[email protected]" } ]
I tried both:
jq '[. | {name, email}]'
and
jq '. | [{name, email}]'
which both gave me the output
[ { "name": "John", "email": "[email protected]" } ] [ { "name": "Brad", "email": "[email protected]" } ]
I also saw no options for an array output in the documentations, any help appreciated
Use slurp mode:
o --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.
$ jq -s '.' < tmp.json [ { "name": "John", "email": "[email protected]" }, { "name": "Brad", "email": "[email protected]" } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With