Skip to content

jaq vs jq differ with --slurp #377

@polarathene

Description

@polarathene

With two separate JSON files, jq and jaq presently differ in output. It seems jaq is not merging the inputs into a single array as is expected when using --slurp?

Verified to occur on both current stable and preview releases:

$ jaq --version
jaq 3.0.0-alpha

$ jq --version
jq-1.7.1

The intent is to merge/operate on multiple file inputs as if they were a single array, as jq output shows. jaq output seem to have been processed individually, similar to yq? (which doesn't support an equivalent --slurp flag)

arg-1.json:

[{ "arg": "hello" }]

arg-2.json:

[{ "arg": "world" }]

Reproduction of problem:

$ jq -sr 'map("--arg " + .[].arg) | join(" ")' arg-*.json
--arg hello --arg world

$ jaq -sr 'map("--arg " + .[].arg) | join(" ")' arg-*.json
--arg hello
--arg world

We can see the difference here (no improvement if I remove the wrapping array in the individual files):

$ jq --slurp '.' arg-*.json
[
  [
    {
      "arg": "hello"
    }
  ],
  [
    {
      "arg": "world"
    }
  ]
]

$ jaq --slurp '.' arg-*.json
[
  [
    {
      "arg": "hello"
    }
  ]
]
[
  [
    {
      "arg": "world"
    }
  ]
]

Related help text for -s / --slurp suggests that jaq should also be showing a merged array?:

$ jaq --help | grep slurp
  -s, --slurp               Read (slurp) all input values into one array

$ jq --help | grep slurp
  -s, --slurp               read all inputs into an array and use it as the single input value;
Collapsed for brevity

These two are equivalent though (join is ineffective as they're not treated as within the same array):

$ jq -sr '.[] | map("--arg " + .arg) | join(" ")' arg-*.json
--arg hello
--arg world

$ jaq -sr '.[] | map("--arg " + .arg) | join(" ")' arg-*.json
--arg hello
--arg world

As is this:

$ jq -r 'map("--arg " + .arg) | join(" ")' arg-*.json
--arg hello
--arg world

$ jq -r 'map("--arg " + .arg) | join(" ")' arg-*.json
--arg hello
--arg world

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions