-
-
Notifications
You must be signed in to change notification settings - Fork 107
jaq vs jq differ with --slurp #377
Description
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:
- https://github.com/01mf02/jaq/releases/tag/v2.3.0
- https://github.com/01mf02/jaq/releases/tag/v3.0.0-alpha
$ jaq --version
jaq 3.0.0-alpha
$ jq --version
jq-1.7.1The 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 worldWe 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 worldAs 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