Home > front end >  Combine JSON arrays based on common key using Jolt
Combine JSON arrays based on common key using Jolt

Time:04-27

My JSON object looks like following:

{
  "array1": [
    {
      "key1": "value1", // common key
      "key2": "value2",
      "key3": "value3"
    },
    {
      "key1": "value1", // common key
      "key2": "value2",
      "key3": "value3"
    }
  ],
  "includes": {
    "array2": [
      {
        "key4": "value1", // common key
        "key5": "value5"
      },
      {
        "key4": "value1", // common key
        "key5": "value5"
      }
    ]
  }
}

I need to have the output in following format -

[ 
  {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3",
    "key5": "value5"  // this comes from joining with array 2 based on key1 & key4
  }, 
  {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3",
    "key5": "value5"  // this comes from joining with array 2 based on key1 & key4
  }
]

Based on enter image description here

  • Related