1

A little more sophisticated as my question mentioned below. I learned to use arrays more, but it screws things up too.

Input:

{
  "a": [
    {
      "b": "c",
      "d": "e"
    },
    {
      "b": "f",
      "d": "g"
    }
  ],
  "h": [
    {
      "b": "c",
      "i": "j"
    },
    {
      "b": "f",
      "i": "k"
    }
  ]
}

desired output:

{
  "l": [
    {
      "b": "c",
      "d": "e",
      "i": "j"
    },
    {
      "b": "f",
      "d": "g",
      "i": "k"
    }
  ]
}

Things that I've tried, based up on JQ How to merge multiple objects into one

{ x: [ inputs | .a[] | { (.h[]): .i } ] | add}
peak
  • 105,803
  • 17
  • 152
  • 177
JdeHaan
  • 332
  • 6
  • 19

1 Answers1

1

The key to a simple solution is transpose:

[.a, .h]
| transpose
| map(add)
| {l: .}
peak
  • 105,803
  • 17
  • 152
  • 177