Search code examples
mulemule-studiomule-componentdataweaveanypoint-studio

Merge 2 or more arrays in single payload


This could be a very simple problem, but I'm not getting the desired output using dataweave 1.0. How can I merge multiple arrays (example below has only 2 arrays but it can be more) into a single object using dw 1.0?

//Input
    [
      {
        "value": [
          {
            "key1": 111,
            "val1": "AAA"
          },
          {
            "key1": 222,
            "val1": "BBB"
          }
        ]
      },
      {
        "value": [
          {
            "key1": 333,
            "val1": "CCC"
          }
        ]
      }
    ]

//Desired Output
{
  "value": [
    {
      "key1": 111,
      "val1": "AAA"
    },
    {
      "key1": 222,
      "val1": "BBB"
    },
    {
      "key1": 333,
      "val1": "CCC"
    }
  ]
}

Solution

  • value: flatten (payload.value)