I have a JSON from source and I am trying to write a JOLT to flatten this data and convert it in to records so that I can insert it in to a Table.
I have already written a JOLT by referring to my previous queries, but unbale to get desired output.
This question is different from Jolt to transform a multilayered Nested JSON to flat JSON because there the nesting is different and also it do not have optional nodes.
Input JSON
{
"CustomerMaster": {
"Rootnode": {
"KUNNR": "0000028790",
"NAME1": "NV Solucious",
"LAND1": "BE",
"SalesArea": [
{
"VKORG": "0200",
"VTWEG": "00",
"SPART": "00"
},
{
"VKORG": "4932",
"VTWEG": "00",
"SPART": "00",
"AUFSD1": "FT",
"PartnerFunction": [
{
"PARVW": "ZP",
"PARZA": "000",
"KUNN2": "0000028790"
},
{
"PARVW": "ZS",
"PARZA": "000",
"KUNN2": "90010523"
}
]
},
{
"VKORG": "4932",
"VTWEG": "10",
"SPART": "00",
"Indicator": {
"IsDistributionCenter": "X"
},
"PartnerFunction": {
"PARVW": "ZS",
"PARZA": "000",
"KUNN2": "90010523"
}
}
]
}
}
}
Desired Output
[ {
"KUNNR": "0000028790",
"NAME1": "NV Solucious",
"LAND1": "BE",,
"VKORG": "0200",
"VTWEG": "00",
"SPART": "00",
}, {
"KUNNR" : "0000028790",
"NAME1" : "NV Solucious",
"LAND1" : "BE",
"VKORG" : "0200",
"VTWEG" : "00",
"SPART" : "00",
"AUFSD1": "FT",
"PARVW": "ZP",
"PARZA": "000",
"KUNN2": "0000028790"
}, {
"KUNNR" : "0000028790",
"NAME1" : "NV Solucious",
"LAND1" : "BE",
"VKORG" : "0200",
"VTWEG" : "00",
"SPART" : "00",
"AUFSD1": "FT",
"PARVW": "ZS",
"PARZA": "000",
"KUNN2": "90010523"
}, {
"KUNNR" : "0000028790",
"NAME1" : "NV Solucious",
"LAND1" : "BE",
"VKORG" : "4932",
"VTWEG" : "10",
"SPART" : "00",
"IsDistributionCenter": "X",
"PARVW": "ZS",
"PARZA": "000",
"KUNN2": "90010523"
}]
I am not getting desired output using the JOLT provided above and need your help to write a JOLT to get desired output.
2
Answers
The answer provided by @BarbarosÖzhan in Jolt to transform a multilayered Nested JSON to flat JSON is nearly perfect; it only misses a small detail for the "Indicator" field.
Here is the completed Jolt (I only added a few rows):
Modifying a above jolt provided by @LucaBiscotti and @BarbarosÖzhan little bit to handle all cases.