Suppose I'd like to parse a JSON array and output its members:
echo '[4,"foo", "[]",[],{"hi": "world"}]' | jq ".[]"
There are a few conventions for newline-delimited JSON values, but this requires having a JSON parser. Fortunately, the NUL delimiter convention is pretty wide-spread and makes it easy for another process to split the values.
Unfortunately, jq only has the --raw-output0, which removes quotes from strings.
echo '[4,"foo", "[]",[],{"hi": "world"}]' | jq ".[]" --raw-output0
As a result:
- Some entries of the output are no longer parseable as JSON (e.g.
"foo" → foo)
- Certain entries are serialized in the same way, making it impossible to recover the original data (e.g.
"[]" and [] both serialize to []).
This could be solved with a flag like --output0 that applies the NUL delimiter without raw formatting.
Suppose I'd like to parse a JSON array and output its members:
There are a few conventions for newline-delimited JSON values, but this requires having a JSON parser. Fortunately, the NUL delimiter convention is pretty wide-spread and makes it easy for another process to split the values.
Unfortunately,
jqonly has the--raw-output0, which removes quotes from strings.As a result:
"foo"→foo)"[]"and[]both serialize to[]).This could be solved with a flag like
--output0that applies the NUL delimiter without raw formatting.