0
votes

I am trying to map some existing data into an array :-

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

I want to be able to map the values array into a target field in my payload but filter out only those which are of key type 'Domain'.

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

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

I've tried the Dataweave below but I get an array of arrays :-

%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
}

Can anyone suggest what the right Dataweave might be for this type of query

1
the sample input json seems incomplete, please post a full example so we can reproduce with your datweave. - utechtzs

1 Answers

2
votes

You could try using the flatten function.

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