Hi All
We are receiving data in JSON format (Nested and optional Nodes). I have written a JOLT to transform/flatten this JSON but not able to get desired result.
I need help to fix JOLT to get desired output.
Input JSON - Node - PartnerFunction and Indicator are optional.
{
"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"
}]
JOLT Created so far -
[
{
"operation": "shift",
"spec": {
"CustomerMaster": {
"Rootnode": {
"*": "else1.&",
"SalesArea": {
"*": {
"*": "&1.else2.&",
"Indicator": { //Added the indicator field
"*": "&2.else2.&"
},
"PartnerFunction": {
"*": {
"*": "&3.&2[&1].&"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"PartnerFunction": {
"*": {
"@(3,else1)": { "*": "&4[&1].&" },
"@(2,else2)": { "*": "&4[&1].&" },
"*": "&3[&1].&"
}
}
}
}
},
{ // get rid of the outermost keys
"operation": "shift",
"spec": {
"*": {
"*": ""
}
}
}
]
Using this JOLT , I am getting this output which is not the desired output.