cancel
Showing results for 
Search instead for 
Did you mean: 

Flattening multiple array entities in JSON Object

arvindnsn
Contributor

Hello,

I am trying to flatten multiple array attributes from a JSON Document. Below is the JSON document and the expected output.

{
“TransactionId”: 55499,
“ReceiptNo”: 1123,
“Location”: “xxxx-xxxxx”,
“Total”: 8.08,
“TotalGross”: 7.46,
“TransactionMedias”: [
{
“MediaId”: 99862,
“MediaNo”: 6,
“MediaValue”: 8.08,
},
{
“MediaId”: 99863,
“MediaNo”: 498,
“MediaValue”: 0.62,
}
],
“TransactionItems”: [
{
“ItemID”: 356391,
“ProductID”: 113900,
“Quantity”: 1,
“Total”: 5.94,
“TotalGross”: 5.49,
“TotalTax”: 0.45,
},
{
“ItemID”: 356392,
“ProductID”: 100097,
“Quantity”: 1,
“Total”: 0,
“TotalGross”: 0,
“TotalTax”: 0,
},
{
“ItemID”: 356393,
“ProductID”: 100097,
“Quantity”: 1,
“Total”: 0.64,
“TotalGross”: 0.59,
“TotalTax”: 0.05,
}
}

I have attached an Excel file with the source JSON Document and the expected output in 2 separate tabs.

Thanks
Aravind NMulti_Array.xlsx (9.7 KB)

8 REPLIES 8

tstack
Former Employee

You could also concatenate the two arrays together and then use a single JsonSplitter on the resulting array:

$TransactionItems.concat($TransactionMedias)

The Copy/Union can also be removed then as well.

Here’s a pipeline using Tim’s tip:

JSON flatten 3_2018_11_29.slp (10.9 KB)

Thanks a lot. Nice to learn to concat the arrays and manipulate them. The attached pipeline is exactly what i needed. Thanks again.

Thank you for the Solution. That works and helps.