1

How can I use jq to combine the two files above, into a single array, by merging each object?

I've found combine array of objects from two files with jq under specific key 1.4 but this is for a specific key.

I've tried:

jq -n '{ combined: (transpose | map(add)) }' a.json b.json jq: error (at <unknown>): Cannot iterate over null (null) 

Input:

 ==> a.json <== [ { "datetime": "2019-12-08 11:34" }, { "datetime": "2019-12-08 11:35" }, { "datetime": "2019-12-08 12:03" } ] ==> b.json <== [ { "command": "cat test.txt" }, { "command": "cat test2.txt" }, { "command": "cat test3.txt" } ] 

Desired output:

 [ { "command": "cat test.txt", "datetime": "2019-12-08 11:34" }, { "command": "cat test2.txt", "datetime": "2019-12-08 11:35" }, { "command": "cat test3.txt", "datetime": "2019-12-08 12:03" } ] 
0

1 Answer 1

2

Just slurp them. -n is for null input, and is overkill for this trivial task.

jq -s 'transpose | map(add)' a.json b.json 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.