【问题标题】:Issues in merging the JSON payloads in Dataweave在 Dataweave 中合并 JSON 有效负载的问题
【发布时间】: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 [])
}

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

谢谢!!

【问题讨论】:

    标签: json mule dataweave


    【解决方案1】:

    我首先将数组展平,然后将其用作主数据编织中的嵌套地图!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多