我在列表变量中添加了来自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 [])
}
,但未返回预期输出。有人可以帮我吗?
谢谢!
答案 0 :(得分:0)
首先将数组展平,然后将其用作主dataweave中的嵌套映射,就可以使它起作用!