0

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

      "categories": [
            {
                "value": [
                    "System"
                ],
                "displayName": "API type",
                "tagType": "category",
                "dataType": "enum",
                "key": "API type"
            },
            {
                "value": [
                    "Merchandising"
                ],
                "displayName": "Domain",
                "tagType": "category",
                "dataType": "enum",
                "key": "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 可能是什么

4

1 回答 1

2

您可以尝试使用 flatten 功能。

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

于 2019-01-22T16:56:40.223 回答