[英]Jolt how to include object outside list and add it to each object of list
我有一個數組,我必須迭代並將列表外的對象附加到列表內的每個對象。 它沒有正確發生。 由於產品是一個數組,如果每個對象有多個對象,我需要有該對象的 typeId。
請求:
[
{
"offers": [
{
"type": {
"id": "5"
},
"offerings": [
{
"id": "10"
},
{
"id": "9"
}
]
},
{
"type": {
"id": "3"
},
"offerings": [
{
"id": "11"
}
]
},
{
"type": {
"id": "2"
},
"offerings": [
{
"id": "14"
},
{
"id": "16"
}
]
}
]
}
]
我的規格:
[
{
"operation": "shift",
"spec": {
"*": {
"offers": {
"*": {
"type": {
"id": "[&4].[&2].typeId"
},
"offerings": {
"*": {
"id": "[&3].[&1].offerId"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
}
]
現在回復:
[
{
"typeId": "5",
"offerId": "10"
},
{
"offerId": "9",
"typeId": "3"
},
{
"typeId": "2"
},
{
"offerId": "11"
},
{
"offerId": "14"
},
{
"offerId": "16"
}
]
預期:
[
{
"typeId": "5",
"offerId": "10"
},
{
"typeId": "5",
"offerId": "9"
},
{
"typeId": "3",
"offerId": "11"
},
{
"typeId": "2",
"offerId": "14"
},
{
"typeId": "2",
"offerId": "16"
}
]
請幫助實現預期。
您可以將"id": "[&4].[&2].typeId"
鍵值對"id": "[&4].[&2].typeId"
到標記為"offerings"
鍵名的對象中作為"@(2,type.id)": "[&3].[&1].typeid"
以便根據需要組合它們,例如下面的
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"offerings": {
"*": {
"@(2,type.id)": "[&3].[&1].typeid",
"*": "[&3].[&1].offer&"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.