在 Dataweave 中合并 JSON 有效载荷的问题

Issues in merging the JSON payloads in Dataweave

我有一个下面的 JSON 数组响应来自添加到列表变量中的 foreach 组件:

[{
  "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 响应的名称字段与第一个 [=51= 的文档名称匹配时才映射对象] 响应并需要从最终响应中过滤掉 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"
                }
            ]
 }
  ]
}

必须从最终响应中删除索引数据。我尝试使用以下数据编织实现此目的:

%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 [])
}

但它没有返回预期的输出。任何人都可以帮助我吗?

谢谢!!

我通过首先展平数组然后将其用作主数据编织中的嵌套映射来使其工作!!