[英]Jolt how to include object outside list and add it to each object of list
I have an array which I have to iterate and append object that is outside the list to each of the object inside list.我有一个数组,我必须迭代并将列表外的对象附加到列表内的每个对象。 It is not happening properly.
它没有正确发生。 Since offerings is an array if it has multiple objects to each object I need to have typeId of that object.
由于产品是一个数组,如果每个对象有多个对象,我需要有该对象的 typeId。
Request :请求:
[
{
"offers": [
{
"type": {
"id": "5"
},
"offerings": [
{
"id": "10"
},
{
"id": "9"
}
]
},
{
"type": {
"id": "3"
},
"offerings": [
{
"id": "11"
}
]
},
{
"type": {
"id": "2"
},
"offerings": [
{
"id": "14"
},
{
"id": "16"
}
]
}
]
}
]
My spec :我的规格:
[
{
"operation": "shift",
"spec": {
"*": {
"offers": {
"*": {
"type": {
"id": "[&4].[&2].typeId"
},
"offerings": {
"*": {
"id": "[&3].[&1].offerId"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
}
]
Response now :现在回复:
[
{
"typeId": "5",
"offerId": "10"
},
{
"offerId": "9",
"typeId": "3"
},
{
"typeId": "2"
},
{
"offerId": "11"
},
{
"offerId": "14"
},
{
"offerId": "16"
}
]
Expected :预期:
[
{
"typeId": "5",
"offerId": "10"
},
{
"typeId": "5",
"offerId": "9"
},
{
"typeId": "3",
"offerId": "11"
},
{
"typeId": "2",
"offerId": "14"
},
{
"typeId": "2",
"offerId": "16"
}
]
Please help to achieve as expected.请帮助实现预期。
You can transfer "id": "[&4].[&2].typeId"
key-value pair into the object tagged "offerings"
key name as "@(2,type.id)": "[&3].[&1].typeid"
in order to combine them as desired such like the below one您可以将
"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.