From two different flows I am getting a json output payload and what to combine them based on a common key. The keys are dynamic, so I want to write a generic dataweave that will work for any key.
Input-1:
[
{
"CustomerID": "123",
"Name": "Maria",
"Phone": "030-0074321"
},
{
"CustomerID": "56654",
"Name": "sdf",
"Phone": "030-6877452"
}
]
Input-2:
[
{
"OrderID": "10643",
"CustomerID": "123",
"Price": "200"
},
{
"OrderID": "10692",
"CustomerID": "123",
"Price": "566"
},
{
"OrderID": "10702",
"CustomerID": "56654",
"Price": "546"
}
]
Expected Output:
[
{
"CustomerID":"123",
"Name":"Maria",
"Phone":"030-0074321",
"Details":[
{
"OrderID":"10643",
"Price":"200"
},
{
"OrderID":"10692",
"Price":"566"
}
]
},
{
"CustomerID":"56654",
"Name":"sdf",
"Phone":"030-6877452",
"Details":[
{
"OrderID":"10702",
"Price":"546"
}
]
}
]
Based on the common key(in this example CustomerID) I want to combine both the inputs. As I mentioned all the keys (CustomerID,Name,Phone,OrderID,Price) are not same all the time, they are dynamic.
Can someone help me write a dynamic dataweave code?
Thanks in advance
