Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jq to convert json array to jsonl format

I have json like this:

[ {"one": 1}, {"two": 2}]

and wish to convert it to this format:

{"one": 1}
{"two": 2}

to facilitate indexing it into ElasticSearch. (latter is called 'jsonl' format). JQ is my tool of preference but I can't figure out how to do this. Thanks

like image 627
David Avatar asked Feb 09 '18 17:02

David


1 Answers

The key is the -c command-line option, which produces JSONL:

jq -c '.[]' test_array.json
like image 161
peak Avatar answered Sep 27 '22 20:09

peak