cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Flattening and Mapping Complex JSON

murphy-brian
New Contributor III

We have a complex JSON object which has the columns information in one array and the row values in another. We would like the output to simply have the merged structure with value of the โ€œTitleโ€ attribute held in the โ€œmyColsโ€ as the key and the value from the โ€œmyRows.Cells.valueโ€ mapped.

We would like a row for each myRows element. Weโ€™d like to do this without using the absolute index numbers of either and leverage the โ€œmyCols.idโ€ and โ€œmyRows.cells.columnIdโ€ which are how they align. The purpose of this is to have a dynamic source and which can have any number of columns that could eventually create a results table and insert the rows.

Any ideas?

[
{
โ€œmyColsโ€: [
{
โ€œidโ€: 7169064356341636,
โ€œversionโ€: 0,
โ€œindexโ€: 0,
โ€œtitleโ€: โ€œORG_VALUE_SRCโ€,
โ€œtypeโ€: โ€œTEXT_NUMBERโ€,
โ€œprimaryโ€: true,
โ€œvalidationโ€: false,
โ€œwidthโ€: 150
},
{
โ€œidโ€: 1539564822128516,
โ€œversionโ€: 0,
โ€œindexโ€: 1,
โ€œtitleโ€: โ€œORG_VALUE_TGTโ€,
โ€œtypeโ€: โ€œTEXT_NUMBERโ€,
โ€œvalidationโ€: false,
โ€œwidthโ€: 150
},
{
โ€œidโ€: 6043164449499012,
โ€œversionโ€: 0,
โ€œindexโ€: 2,
โ€œtitleโ€: โ€œCREATE_DATEโ€,
โ€œtypeโ€: โ€œTEXT_NUMBERโ€,
โ€œvalidationโ€: false,
โ€œwidthโ€: 150
},
{
โ€œidโ€: 3791364635813764,
โ€œversionโ€: 0,
โ€œindexโ€: 3,
โ€œtitleโ€: โ€œUPDATE_DATEโ€,
โ€œtypeโ€: โ€œDATEโ€,
โ€œvalidationโ€: false,
โ€œwidthโ€: 150
}
],
โ€œmyRowsโ€: [
{
โ€œidโ€: 7737866304415620,
โ€œrowNumberโ€: 1,
โ€œexpandedโ€: true,
โ€œcreatedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œmodifiedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œcellsโ€: [
{
โ€œcolumnIdโ€: 7169064356341636,
โ€œvalueโ€: 1400076,
โ€œdisplayValueโ€: โ€œ1400076โ€
},
{
โ€œcolumnIdโ€: 1539564822128516,
โ€œvalueโ€: โ€œ1400076GBPโ€,
โ€œdisplayValueโ€: โ€œ1400076GBPโ€
},
{
โ€œcolumnIdโ€: 6043164449499012
},
{
โ€œcolumnIdโ€: 3791364635813764,
โ€œvalueโ€: โ€œ2018-02-28โ€
}
]
},
{
โ€œidโ€: 2108366770202500,
โ€œrowNumberโ€: 2,
โ€œsiblingIdโ€: 7737866304415620,
โ€œexpandedโ€: true,
โ€œcreatedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œmodifiedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œcellsโ€: [
{
โ€œcolumnIdโ€: 7169064356341636,
โ€œvalueโ€: 1400076,
โ€œdisplayValueโ€: โ€œ1400076โ€
},
{
โ€œcolumnIdโ€: 1539564822128516,
โ€œvalueโ€: โ€œ1400076EURโ€,
โ€œdisplayValueโ€: โ€œ1400076EURโ€
},
{
โ€œcolumnIdโ€: 6043164449499012
},
{
โ€œcolumnIdโ€: 3791364635813764,
โ€œvalueโ€: โ€œ2018-02-28โ€
}
]
},
{
โ€œidโ€: 6611966397572996,
โ€œrowNumberโ€: 3,
โ€œsiblingIdโ€: 2108366770202500,
โ€œexpandedโ€: true,
โ€œcreatedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œmodifiedAtโ€: โ€œ2018-12-18T17:48:08Zโ€,
โ€œcellsโ€: [
{
โ€œcolumnIdโ€: 7169064356341636,
โ€œvalueโ€: 1400077,
โ€œdisplayValueโ€: โ€œ1400077โ€
},
{
โ€œcolumnIdโ€: 1539564822128516,
โ€œvalueโ€: โ€œ1400077GBPโ€,
โ€œdisplayValueโ€: โ€œ1400077GBPโ€
},
{
โ€œcolumnIdโ€: 6043164449499012
},
{
โ€œcolumnIdโ€: 3791364635813764,
โ€œvalueโ€: โ€œ2018-02-28โ€
}
]
}
]
}
]

9 REPLIES 9

Ajay_Chawda
Contributor

Hi Brian,
Below screen shot you are trying to achieve?
image Image

Sorry should have provided the structure too

More like this:
[
[
{
โ€œnewRowsโ€: [
{
โ€œrowNumberโ€: 1,
โ€œORG_VALUE_SRCโ€: โ€œ1400076โ€,
โ€œORG_VALUE_TGTโ€: โ€œ1400076GBPโ€,
โ€œCREATE_DATEโ€: โ€œ2018-02-28โ€,
โ€œUPDATE_DATEโ€: โ€œ2018-02-28โ€
},
{
โ€œrowNumberโ€: 2,
โ€œORG_VALUE_SRCโ€: โ€œ1400076โ€,
โ€œORG_VALUE_TGTโ€: โ€œ1400076EURโ€,
โ€œCREATE_DATEโ€: โ€œ2018-02-28โ€,
โ€œUPDATE_DATEโ€: โ€œ2018-02-28โ€
},
{
โ€œrowNumberโ€: 3,
โ€œORG_VALUE_SRCโ€: โ€œ1400077โ€,
โ€œORG_VALUE_TGTโ€: โ€œ1400077GBPโ€,
โ€œCREATE_DATEโ€: โ€œ2018-02-28โ€,
โ€œUPDATE_DATEโ€: โ€œ2018-02-28โ€
}
]
}
]
]
Basically a row for every source row using the โ€œTitleโ€ as the key and โ€œValueโ€ from โ€œmyRows.cellsโ€ as the value. My need is grander than this but figured if someone could steer me in the right direction we could take it from there.
Thanks

Hi Brian,
I tried to achieve your requirement by using script snap.

readComplexJson_2018_12_26.slp (12.3 KB)

Thank you that helped and also validated that it needed to be a script block. Wanโ€™t sure if there was any magic jsonPath or other Snap that could do this without scripting. Do you know if there are any limitations on using script blocks is large data streams? Just trying to understand best practices when using Script Blocks.