我做不到,这里需要一些社区的智慧。请在下面找到源数据和期望的结果。我目前正在熟悉JSONata。
我在JSONata文档中尝试了几乎所有的组合,但是我得到了奇怪的结果。
源数据
[
{
"id": 784521,
"name": "T-Shirt - Red / 60 XXL",
"properties": [
{
"name": "customization",
"value": "Text, Logo"
},
{
"name": "customization_text",
"value": "John Doe"
},
{
"name": "customization_text_pos",
"value": "Left"
},
{
"name": "customization_logo",
"value": "https://https://picsum.photos/200/300"
},
{
"name": "customization_logo_pos",
"value": "Right"
}
],
"quantity": 8,
"sku": "888-111"
},{
"id": 154857,
"name": "Pullover - Blue / 48 L",
"properties": [
{
"name": "customization",
"value": "Text"
},
{
"name": "customization_text",
"value": "John Doe"
},
{
"name": "customization_text_pos",
"value": "Right"
}
],
"quantity": 4,
"sku": "555-111"
}
]期望结果
{
"products": [
{
"name": "T-Shirt - Red / 60 XXL",
"quantity": 8,
"customization": "Text, Logo",
"customization_text": "John Doe",
"customization_text_pos": "Left",
"customization_logo": "https://https://picsum.photos/200/300",
"customization_logo_pos": "Right"
},
{
"name": "Pullover - Blue / 48 L",
"quantity": 4,
"customization": "Text",
"customization_text": "John Doe",
"customization_text_pos": "Right",
"customization_logo": "",
"customization_logo_pos": ""
}
]
}发布于 2022-11-04 12:08:00
我不确定用空字符串值填充丢失的属性有多重要,但如果不是--将属性数组还原为对象,则可以实现以下结果:
{
"products": $$.(
$item := $;
properties{
"name": $item.name,
"quantity": $item.quantity,
name: value
}
)
}https://stackoverflow.com/questions/74316521
复制相似问题