0

I need help appending a value to an array using jq. I tried appending the json using this command below.

jq '.[] |= .+ {"ID": "C", "location":"France"}' original.json > new.json

The original.json contains this array:

[
{"ID": "A", "location":"Canada"},
{"ID": "B", "location":"Singapore"}
]

but I end up replacing the current values with the new inserted value. Can anyone help me with this?

Corgiz
  • 1
  • 1
    1) You're modifying each element of the root (`.[]`) when you want to modify the root (`.`), and 2) you can't add (`+`) an object and an array. [Fix](https://jqplay.org/s/LxhgXNEZEH) – ikegami Feb 23 '22 at 05:47

0 Answers0