【发布时间】:2018-09-17 02:30:57
【问题描述】:
我在列表变量中添加了来自 foreach 组件的以下 JSON 数组响应:
[{
"DocumentName": "Test1",
"renditions": [
{
"rendition": "indexData"
},
{
"rendition": "48x48_GIF"
},
{
"rendition": "80x80_JPG"
},
{
"rendition": "100x100_JPG"
}
]
}, {
"DocumentName": "Test23",
"renditions": [
{
"rendition": "indexData"
},
{
"rendition": "Preview"
},
{
"rendition": "Native File"
}
]
}]
我有另一个服务正在向我发送 JSON 响应,如下所示:
{
"results": [
{
"ID": "1",
"ImageID": "2",
"Name": "Test1",
"Owner": "sysadmin",
"Author": "sysadmin",
"Creator": "sysadmin"
},
{
"ID": "2",
"ImageID": "23",
"Name": "Test23",
"Owner": "sysadmin",
"Author": "sysadmin",
"Creator": "sysadmin"
}
]
}
我想要的是根据条件组合上述两个有效负载,并且仅当第二个 JSON 响应中的 Name 字段与第一个 JSON 响应的 DocumentName 匹配并且需要过滤掉 indexData 再现时才映射对象来自最终响应,最终响应必须如下:
{
"results": [
{
"ID": "1",
"ImageID": "2",
"Name": "Test1",
"Owner": "sysadmin",
"Author": "sysadmin",
"Creator": "sysadmin"
"links": [
{
"rel": "48x48_GIF",
"href": "/abc/48x48_GIF"
},
{
"rel": "80x80_JPG",
"href": "/abc/80x80_JPG"
},
{
"rel": "100x100_GIF",
"href": "/abc/100x100_GIF"
}
]
},
{
"ID": "2",
"ImageID": "23",
"Name": "Test23",
"Owner": "sysadmin",
"Author": "sysadmin",
"Creator": "sysadmin"
"links": [
{
"rel": "Preview",
"href": "/abc/Preview"
},
{
"rel": "Native File",
"href": "/abc/Native File"
}
]
}
]
}
必须从最终响应中删除 indexData。我尝试使用以下数据编织实现此目的:
%dw 1.0
%output application/json
---
{
"results": (payload.searchResults pluck ({
"ID": $.xAH_StoreItemNumber,
"ImageID": $.dID,
"Name": $.dDocName,
"Owner": $.dDocOwner,
"Author": $.dDocAuthor,
"Creator": $.dDocCreator,
"links": flowVars.setRenditionsResponse.renditions map ((renditions, indexofRenditions) -> {
"rel": renditions.rendition
}) ++
[{
"rel": "retail-item",
"href": (p('ah.packshots.api.url') ++ $.xAH_StoreItemNumber)
}]
}) when (sizeOf payload) >= 1 otherwise [])
}
但它没有返回预期的输出。任何人都可以帮助我吗?
谢谢!!
【问题讨论】: