目前我有以下输入 JSON。“temp”对象已在默认规范的帮助下添加。
{
"items": [
{
"description": "myDescription",
"attributes": [
{
"identifier": "colour",
"type": "attribute",
"values": [
"DE"
],
"hint": "1"
},
{
"identifier": "pin",
"type": "attribute",
"values": [
"4711"
],
"hint": "1"
},
{
"identifier": "price",
"type": "price",
"values": [
"77.27"
],
"hint": "1"
},
{
"identifier": "weight",
"type": "attribute",
"values": [
"0.47"
],
"hint": "1"
},
{
"identifier": "status",
"type": "attribute",
"values": [
"active"
],
"hint": "1"
}
]
}
],
"temp": {
"hint": "1",
"identifier": "additionalDescription",
"values": [
{
"lang": "de",
"value": "temp"
},
{
"lang": "en",
"value": "temp"
},
{
"lang": "fr",
"value": "temp"
},
{
"lang": "it",
"value": "temp"
},
{
"lang": "es",
"value": "temp"
}
],
"type": "attribute"
}
}
期望的输出:
{
"items": [
{
"description": "myDescription",
"attributes": [
{
"identifier": "colour",
"type": "attribute",
"values": [
"DE"
],
"hint": "1"
},
{
"identifier": "pin",
"type": "attribute",
"values": [
"4711"
],
"hint": "1"
},
{
"identifier": "price",
"type": "price",
"values": [
"77.27"
],
"hint": "1"
},
{
"identifier": "weight",
"type": "attribute",
"values": [
"0.47"
],
"hint": "1"
},
{
"identifier": "status",
"type": "attribute",
"values": [
"active"
],
"hint": "1"
},
{
"hint": "1",
"identifier": "additionalDescription",
"values": [
{
"lang": "de",
"value": "myDescription"
},
{
"lang": "en",
"value": "myDescription"
},
{
"lang": "fr",
"value": "myDescription"
},
{
"lang": "it",
"value": "myDescription"
},
{
"lang": "es",
"value": "myDescription"
}
],
"type": "attribute"
}
]
}
]
}
我正在寻找的规范应满足两个要求:
- 将“新”对象集成到属性数组中。
- 将值“temp”替换为描述字段的值,该字段可以在 json 顶部找到。
不幸的是,我已经在努力将数组正确地放入输出 JSON 中,更不用说覆盖值“temp”了
[
{
"operation": "shift",
"spec": {
"items": {
"*": {
"description": "&2.myDescription",
"attributes": {
"@(3,temp)": "&3.&2.&",
"*": "&3.&2.&"
}
}
}
}
}
]
非常感谢任何帮助。另外,我也很高兴收到有关第一个要求的提示。每当涉及数组时,我在构建 RHS(右侧)时总是很困难。