01mf02 / jaq

A jq clone focussed on correctness, speed, and simplicity
MIT License
2.7k stars 67 forks source link

Different behavior with 'add' filter #190

Closed darkmoloko closed 1 month ago

darkmoloko commented 3 months ago

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"
}
wader commented 3 months ago

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]
01mf02 commented 1 month ago

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

01mf02 commented 1 month ago

@wader: 😱 for 23