I’m facing an issue with implementing Jolt Spec to transform this input.
input:
<code>{
"id": 12345,
"category": 2,
"productAttributes": {
"data": [
{
"name": "Size",
"slug": "size",
"value": "10"
},
{
"name": "Color",
"slug": "color",
"value": "Grey"
}
]
}
}
</code>
<code>{
"id": 12345,
"category": 2,
"productAttributes": {
"data": [
{
"name": "Size",
"slug": "size",
"value": "10"
},
{
"name": "Color",
"slug": "color",
"value": "Grey"
}
]
}
}
</code>
{
"id": 12345,
"category": 2,
"productAttributes": {
"data": [
{
"name": "Size",
"slug": "size",
"value": "10"
},
{
"name": "Color",
"slug": "color",
"value": "Grey"
}
]
}
}
spec:
<code>[
{
"operation": "shift",
"spec": {
"productAttributes": {
"data": {
"*": {
"slug": "attributes[#2].key",
"value": "attributes[#2].value",
"name": "attributes[#2].name"
}
}
}
}
}
]
</code>
<code>[
{
"operation": "shift",
"spec": {
"productAttributes": {
"data": {
"*": {
"slug": "attributes[#2].key",
"value": "attributes[#2].value",
"name": "attributes[#2].name"
}
}
}
}
}
]
</code>
[
{
"operation": "shift",
"spec": {
"productAttributes": {
"data": {
"*": {
"slug": "attributes[#2].key",
"value": "attributes[#2].value",
"name": "attributes[#2].name"
}
}
}
}
}
]
desired output:
<code>{
"attributes" : [ {
"key" : "size",
"value" : "10",
"name" : "Size"
}, {
"key" : "color",
"value" : "Grey",
"name" : "Color"
}, {
"key" : "category",
"value" : "2",
"name" : "Category"
} ]
}
</code>
<code>{
"attributes" : [ {
"key" : "size",
"value" : "10",
"name" : "Size"
}, {
"key" : "color",
"value" : "Grey",
"name" : "Color"
}, {
"key" : "category",
"value" : "2",
"name" : "Category"
} ]
}
</code>
{
"attributes" : [ {
"key" : "size",
"value" : "10",
"name" : "Size"
}, {
"key" : "color",
"value" : "Grey",
"name" : "Color"
}, {
"key" : "category",
"value" : "2",
"name" : "Category"
} ]
}
I want to add the category in root to the attributes array. The value will be taken from the category property. key and name will be filled as static.
Could you help me? Thanks.
New contributor
Enes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.