Splitting JSON input to multiple JSON output based on an array in the input
Hi Team,
Is there is simple way to take an input JSON record and produce the output that is shown below?
This is a simplified version of what is trying to be achieved…
The input record contains two variables and an array of “skus” consisting of items with two variables, a “skucode” and a “shade”.
Each output record is a superset of the input record. Each output record promotes one of the array items above the array to the same level as the two variables in the input record, as shown in the example below.
Input:
{
“code”: “ABCD”,
“name”: “Product A”,
“sku”: [
{
“skucode”: “ABCD12”,
“shade”: “green”
},
{
“skucode”: “ABCD13”,
“shade”: “brown”
},
{
“skucode”: “ABCD14”,
“shade”: “blue”
},
{
“skucode”: “ABCD15”,
“shade”: “red”
},
]
}
Output:
[{
“code”: “ABCD”,
“name”: “Product A”,
“skucode”: “ABCD12”,
“shade”: “green”
“sku”: [
{
“skucode”: “ABCD12”,
“shade”: “green”
},
{
“skucode”: “ABCD13”,
“shade”: “brown”
},
{
“skucode”: “ABCD14”,
“shade”: “blue”
},
{
“skucode”: “ABCD15”,
“shade”: “red”
},
]
},
{
“code”: “ABCD”,
“name”: “Product A”,
“skucode”: “ABCD13”,
“shade”: “brown”
“sku”: [
{
“skucode”: “ABCD12”,
“shade”: “green”
},
{
“skucode”: “ABCD13”,
“shade”: “brown”
},
{
“skucode”: “ABCD14”,
“shade”: “blue”
},
{
“skucode”: “ABCD15”,
“shade”: “red”
},
]
},
{
“code”: “ABCD”,
“name”: “Product A”,
“skucode”: “ABCD14”,
“shade”: “blue”
“sku”: [
{
“skucode”: “ABCD12”,
“shade”: “green”
},
{
“skucode”: “ABCD13”,
“shade”: “brown”
},
{
“skucode”: “ABCD14”,
“shade”: “blue”
},
{
“skucode”: “ABCD15”,
“shade”: “red”
}
]
},
{
“code”: “ABCD”,
“name”: “Product A”,
“skucode”: “ABCD15”,
“shade”: “red”
“sku”: [
{
“skucode”: “ABCD12”,
“shade”: “green”
},
{
“skucode”: “ABCD13”,
“shade”: “brown”
},
{
“skucode”: “ABCD14”,
“shade”: “blue”
},
{
“skucode”: “ABCD15”,
“shade”: “red”
}
]
}
]