jaq icon indicating copy to clipboard operation
jaq copied to clipboard

Different behavior with 'add' filter

Open darkmoloko opened this issue 1 year ago • 1 comments

The concatenation of two objects into a single object is not done when reading objects from files, but it is when using cat and pipe method:

$ echo '{"key1":"value1"}' > i.json
$ echo '{"key2":"value2"}' > j.json

$ jaq -s 'add' i.json j.json 
{
  "key1": "value1"
}
{
  "key2": "value2"
}

$ cat i.json j.json | jaq -s 'add'
{
  "key1": "value1",
  "key2": "value2"
}

darkmoloko avatar Jun 28 '24 09:06 darkmoloko

Seem to be that slurp is per file atm:

$ jaq -- -sc . <(echo 1 2) <(echo 3 4)
[1,2]
[3,4]
$ jaq -- -cs . <(echo 1 2 3 4)
[1,2,3,4]

Fun bonus fact: jq for some reason supports reading values that span two files 🥳😬

$ jq -sc . <(echo -n 1 2) <(echo -n 3 4)
[1,23,4]

wader avatar Jun 28 '24 10:06 wader

@darkmoloko, this behaviour is intentional and the difference with respect to jq is motivated here.

01mf02 avatar Sep 02 '24 07:09 01mf02

@wader: 😱 for 23

01mf02 avatar Sep 02 '24 07:09 01mf02