My request sounds trivial but I could not find a way to do it. I have as input an array of JSON objects:
[
{
\"foo\": 1,
\"bar\": 2
}
Found: it's
map(tostring) | reduce .[] as $item (""; . + $item + "\n")
You also need to use --raw-output.
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"}
99
null
{"foo":"baz"}
$