0
votes

I've currently got a working Transform Message (DataWeave) component in my Mule Project; which returns valid JSON.

What I need now is to update and add to that transformation with additional info from a second (and sometimes more) database payload(s).

I know that you can specify many inputs in the dw script (See DW example tutorial).

%dw 1.0
%input in0 application/json
%input in1 application/json
%input in2 application/json
%output application/xml

[where in0, in1 and in2 are actual input names]

I'm not sure how to apply this method to multiple payloads derived from the database.

My aim is to have my base JSON be built by the first payload:

{
    "code": "some code",
    "title": "some title",
    "description": "some description",
    "keywords": []
}

which works fine.

But now I want the keywords array to be populated by the next payload, to become:

{
    "code": "some code",
    "title": "some title",
    "description": "some description",
    "keywords": [
        "keyword 1", "keyword 2", "keyword x"
    ]
}

How to I map a JSON output in DataWeave from multiple inputs?


Details:

  • Mule EE Version: 3.7.2
  • Anypoint Studio Version: 5.3.0

1
Do I create two transforms and populate them one after another? Do I call the database multiple times and assign their payloads to a Payload object?Möoz
You have to call databases and then assign their payloads to flowVars. Take a look to my answerDavoCoder

1 Answers

1
votes

You have to assign the different payloads to flowVars, so, you can access from your dw script to these variables:

<set-variable variableName="myVar" value="{&quot;key1&quot;:&quot;value1&quot;}" doc:name="Variable"/>
<set-variable variableName="myVar2" value="{&quot;key2&quot;:&quot;value2&quot;}" doc:name="Variable"/>

.

%dw 1.0
%output application/json
---
{
    "a":flowVars.myVar,
    "b":flowVars.myVar2
}