cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting JSON input to multiple JSON output based on an array in the input

CCELC
New Contributor

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”
}
]
}
]

2 REPLIES 2

tlikarish
Employee
Employee

You can do this with the JsonSplitter snap. Here’s a pipeline that demos the example you wrote up.

image

SkuSplitter_2019_02_20.slp (3.8 KB)

Excellent, that’s actually what we needed. Thank you