I have the following JSON including a properties array and I would like to transform it with jolt
JSON INPUT
{
"kind": "product",
"product": {
"id": "product.P-L-0368",
"productNumber": "P-L-0368",
"name": "myProduct"
},
"properties": [
{
"values": [
{
"value": "222"
}
],
"id": "purchase_category",
"type": "string"
},
[
{
"id": "brand",
"type": "string",
"values": [
{
"value": "my_brand",
"language": null,
"unit_of_measure": null
}
]
}
]
]
}
DESIRED OUTPUT
{
"kind": "product",
"product": {
"id": "product.P-L-0368",
"productNumber": "P-L-0368",
"name": "myProduct"
},
"properties": [
{
"values": [
{
"value": "222"
}
],
"id": "purchase_category",
"type": "string"
},
{
"id": "brand",
"type": "string",
"values": [
{
"value": "my_brand",
"language": null,
"unit_of_measure": null
}
]
}
]
}
The problem is, that I do not know how to get rid of the array bracket within the properties array (surrounding the brand object)
2
Answers
If the input is in fixed style, then you can match the second indexed object from the one deeper level such as
As your json.properties is an unindexed array, you could access it like that :
json.properties[1] (assuming you always want to change the second element).
so you could just update the json like this :