How to convert Nested JSON to Flattened JSON using JOLT transform
Hi guys,
I want to convert Nested JSON to Flattened JSON using JOLT transform.
Nested JSON:
{
"data": {
"getBusinessRelationListing": {
"edges": [
"node": {
"id": "1964732",
"name": null,
"code": "CZ01",
"bejoCompany": true,
"legacyVendorId": [],
"locatonType": [
"Commercial"
],
"countries": [
{
"locationCountry": "CZ",
"countryCode": "CZ",
"name": "Czechia",
"parent": {
"shortCode": "EU",
"name": "Europe"
},
"region": "NH"
},
{
"locationCountry": "SK",
"countryCode": "SK",
"name": "Slovakia",
"parent": {
"shortCode": "EU",
"name": "Europe"
},
"region": "NH"
}
]
}
}
]
}
}
}
I am using this JOLT Spec:
[
{
"operation": "shift",
"spec": {
"data": {
"getBusinessRelationListing": {
"edges": {
"*": {
"node": {
"id": "[&2].Id",
"code": "[&2].BusinessRelation",
"name": "[&2].BusinessRelationDisplayName",
"countries": {
"*": {
"locationCountry": "[&4].LocationCountry",
"parent": {
"name": "[&5].LocationCountryName",
"shortCode": "[&5].LocationRegion"
}
}
}
}
}
}
}
}
}
}
]
It is giving output in this format:
[ {
"BusinessRelation" : "CN02",
"BusinessRelationDisplayName" : null,
"Id" : "1964730",
"LocationCountry" : "CN",
"LocationCountryName" : "Africa & Middle East & Asia",
"LocationRegion" : "AMEA"
}, {
"BusinessRelation" : "CZ01",
"BusinessRelationDisplayName" : null,
"Id" : "1964732",
"LocationCountry" : [ "CZ", "SK" ],
"LocationCountryName" : [ "Europe", "Europe" ],
"LocationRegion" : [ "EU", "EU" ]
} ]
But I want output in the below format:
[ {
"BusinessRelation" : "CN02",
"BusinessRelationDisplayName" : null,
"Id" : "1964730",
"LocationCountry" : "CN",
"LocationCountryName" : "Africa & Middle East & Asia",
"LocationRegion" : "AMEA"
}, {
"BusinessRelation" : "CZ01",
"BusinessRelationDisplayName" : null,
"Id" : "1964732",
"LocationCountry" : "CZ" ,
"LocationCountryName" : "Europe",
"LocationRegion" : "EU",
} ,
{
"BusinessRelation" : "CZ01",
"BusinessRelationDisplayName" : null,
"Id" : "1964732",
"LocationCountry" : "SK" ,
"LocationCountryName" : "Europe",
"LocationRegion" : "EU",
} ]
I'm new to JOLT. Please help me
thank you

