如何在Dataweave中将数据映射到Array?

时间:2019-01-22 16:45:21

标签: dataweave mulesoft

我正在尝试将一些现有数据映射到数组中:-

      "categories": [
            {
                "value": [
                    "System"
                ],
                "displayName": "API type",
                "tagType": "category",
                "dataType": "enum",
                "key": "API type"
            },
            {
                "value": [
                    "Merchandising"
                ],
                "displayName": "Domain",
                "tagType": "category",
                "dataType": "enum",
                "key": "Domain"
            }
        ]

我希望能够将values数组映射到我的有效负载中的目标字段中,但仅过滤出键类型为“ Domain”的字段。

So I am trying to get a payload as follows :-

{
  "organizationId": "13445",
  "organizationName": "MyOrg",
  "assetId": "myAPI",
  "businessDomains": [
       "Sales",
       "Marketing",
       "Distribution"
  ]
}

我已经尝试了下面的Dataweave,但是得到了一个数组数组:-

%dw 1.0
%output application/json
---
{
    organizationId: flowVars.v_Org_Id,
    organizationName: flowVars.v_Org_Name,
    assetId: payload.assetId,
    businessDomains: (payload.categories filter ($.categories.key == 'Domain')).value
}

任何人都可以建议对于这种类型的查询合适的Dataweave

1 个答案:

答案 0 :(得分:2)

您可以尝试使用展平功能。

businessDomains: flatten((payload.categories filter ($.key == 'Domain')).value)