JMESPath adding a particular key: value to each object in array

97 Views Asked by At

I'm trying to use a JMESPath query to go from the following,

[
  {
    "key1": true,
    "key2": true
  },
  {
    "key1": true,
    "key2": true
  }
]

to this,

[
  {
    "key1": true,
    "key2": true,
    "key3": "value"
  },
  {
    "key1": true,
    "key2": true,
    "key3": "value"
  }
]

I don't think I need to refer to the parent node, since I already know what key3: "value" is beforehand, and it's the same for each object in the array. How would this typically be done?

1

There are 1 best solutions below

0
J. M. Becker On

I figured out the answer, the merge function can perform this action.

[*].merge(@, {"key3": 'value'})