admin管理员组文章数量:1336643
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)
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)
Share Improve this question asked Nov 19, 2024 at 15:37 Katja BürgerKatja Bürger 351 silver badge6 bronze badges 1 |2 Answers
Reset to default 1If the input is in fixed style, then you can match the second indexed object from the one deeper level such as
[
{
"operation": "shift",
"spec": {
"*": "&", //the elements other than "properties"
"properties": {
"0": "&1",
"1": {
"*": "&2"
}
}
}
}
]
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 :
json.properties[1] = {
"id": "brand",
"type": "string",
"values": [
{
"value": "my_brand",
"language": null,
"unit_of_measure": null
}
]
}
本文标签: joltManipulate objects within a jsonStack Overflow
版权声明:本文标题:jolt - Manipulate objects within a json - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742417632a2471025.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
id = "brand"
may vary I mean ? And do there exist only those two objects nested within the properties array ? – Barbaros Özhan Commented Nov 19, 2024 at 15:49