Skip to main content
KarthiAsokan
Silver ⭐️
Mar 9, 2021 10:01 AM UTC
Solved

Need Jolt Spec to convert matrix json to denormalized json formart

Can anyone please help me a JOLT spec to convert my matrix type json to denormalized json. Please find the below my input json and my expected josn output.

Input Json:

[
{
"attributes": [
{
"name": "brand",
"value": "Patriot Lighting"
},
{
"name": "color",
"value": "Chrome"
},
{
"name": "price",
"value": "49.97 USD"
}
]
},
{
"attributes": [
{
"name": "brand",
"value": "Masterforce"
},
{
"name": "color",
"value": "Green"
},
{
"name": "price",
"value": "99.0 USD"
}
]
}
]

Expected Json output:

[
{
"brand": "Patriot Lighting",
"color": "Chrome",
"price": "49.97 USD"
},
{
"brand": "Masterforce",
"color": "Green",
"price": "99.0 USD"
}
]

I was trying to build JOLT spec to convert this json. But challenge is the json which I have multiple tables with "attributes" tag.

 

@Json @NIFIJOLT 

Thanks in advance!

NIFIJOLT
NIFIJOLTAnswer
Gold ⭐️
Mar 9, 2021 10:28 AM UTC

[
{
"operation": "shift",
"spec": {
"*": {
"attributes": {
"*": {
"@(0,value)": "attributes[#4].@(0,name)"
}
}
}
}
}
]

2 replies

NIFIJOLT
NIFIJOLTAnswer
Gold ⭐️
Mar 9, 2021 10:28 AM UTC

[
{
"operation": "shift",
"spec": {
"*": {
"attributes": {
"*": {
"@(0,value)": "attributes[#4].@(0,name)"
}
}
}
}
}
]

Translate
KarthiAsokan
Silver ⭐️
Mar 9, 2021 11:13 AM UTC

@NIFIJOLT This is working as I expected. Thank you so much!!!

Translate