0

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. Commented Jan 22, 2019 at 17:53

1 Answer 1

2

You could try using the flatten function.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.