I would like to change a field in my json file as specified by another json file. My input file is something like:
{"id": 10, "name": "foo", "some_other_field": "value 1"}
{"id": 20, "name": "bar", "some_other_field": "value 2"}
{"id": 25, "name": "baz", "some_other_field": "value 10"}
I have an external override file that specifies how name
in certain objects should be overridden, for example:
{"id": 20, "name": "Bar"}
{"id": 10, "name": "foo edited"}
As shown above, the override may be shorter than input, in which case the name
should be unchanged. Both files can easily fit into available memory.
Given the above input and the override, I would like to obtain the following output:
{"id": 10, "name": "foo edited", "some_other_field": "value 1"}
{"id": 20, "name": "Bar", "some_other_field": "value 2"}
{"id": 25, "name": "baz", "some_other_field": "value 10"}
Being a beginner with jq
, I wasn't really sure where to start. While there are some questions that cover similar ground (the closest being this one), I couldn't figure out how to apply the solutions to my case.