How to use jq to output JSONL (one independent JSON object per line) How to use jq to output JSONL (one independent JSON object per line) json json

How to use jq to output JSONL (one independent JSON object per line)


The answer to the original question is to use the filter .[] together with the -c command-line option:

$ jq -c '.[]'


If the input array is too large to fit into memory, you can use jq's so-called "streaming parser".

Here is an illustration using a generic approach, that is, it makes no assumptions about the items in the top-level array:

$ echo '[{"foo":"bar"},99,null,{"foo":"baz"}]' |  jq -cn --stream 'fromstream( inputs|(.[0] |= .[1:]) | select(. != [[]]) )'{"foo":"bar"}99null{"foo":"baz"}$ 


Found: it's

map(tostring) | reduce .[] as $item (""; . + $item + "\n")

You also need to use --raw-output.