Skip to content

NUL-delimited output without raw conversion #3448

@lgarron

Description

@lgarron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions