0

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

2
  • 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? Commented Nov 25, 2015 at 4:01
  • You have to call databases and then assign their payloads to flowVars. Take a look to my answer Commented Nov 26, 2015 at 18:22

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. The documentation doesn't mention this, AFAIK.

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.