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

ptaylor
Employee
Employee

What do you mean by โ€œflattenโ€? Whatโ€™s the expected output format? CSV?

The expected output is typical records to load into Oracle DB

ptaylor
Employee
Employee

Try the attached pipeline. It produces JSON in your flat arrangement.

JSON flatten_2018_11_28.slp (21.2 KB)

ptaylor
Employee
Employee

Actually, hereโ€™s a much simpler pipeline to accomplish the same. Note that both of these pipelines resolve the name conflict between the โ€œTotalโ€ and โ€œTotalGrossโ€ fields in the root object vs the TransactionItem objects by renaming either the child fields (first pipeline) or the root fields (second pipeline).
JSON flatten 2_2018_11_28.slp (13.9 KB)