Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert messages to arrays using jq

My messages generator output

$ ./messages.sh
{"a":"v1"}
{"b":"v2"}
{"c":"v3"}
...

Required output

$ ./messages.sh | jq xxxxxx
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Take the first item using ., and the second using input. Wrap them both into array brackets, and provide the -c option for compact output. jq will work through its whole input one by one (or two by two).

./messages.sh | jq -c '[., input]'
[{"a":"v1"},{"b":"v2"}]
[{"c":"v3"},{"d":"v4"}]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading