Q:

jq - merge only single key from second JSON file into main JSON file

Given:
master.json:
{"a":[{"x":1}], "b":1}

extra.json:
{"a":[{"x":2}], "somekey2":2, "somekey3":3}

Expected output:
{
  "a": [
    {
      "x": 1
    },
    {
      "x": 2
    }
  ],
  "b": 1
}

I need to merge into master.json contents of "a" key from extra.json, ignoring all other keys the second JSON may have.
Tried this, but it didn't work
jq -s "add" '.[a] + .[a]' x1 x2

A:

You don't need to slurp them. Without any flags you can access the second input by input keyword.
$ jq '.a += input.a' master.json extra.json 
{
  "a": [
    {
      "x": 1
    },
    {
      "x": 2
    }
  ],
  "b": 1
}

