jq: how to add elements from an array into another array one by one

744 views jq

First array file1:

[{"1":"2"}, {"3":"4"}] 

Second array in file2:

[{"a":"b"}, {"c":"d"}]

I tried "jq -s -c '.[0][] + .[1][]' file1 file2". The result:


However, I want the following:


Thanks for the help.

answered question

1 Answer


An (the?) elegant way:

$ jq -n --argfile f1 file1.json --argfile f2 file2.json -f program.jq

where program.jq is:

| transpose
| map(add)

posted this

Have an answer?


Please login first before posting an answer.