Reputation: 863
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:
Upvotes: 0
Views: 1607
Reputation: 872
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="{"key1":"value1"}" doc:name="Variable"/>
<set-variable variableName="myVar2" value="{"key2":"value2"}" doc:name="Variable"/>
.
%dw 1.0
%output application/json
---
{
"a":flowVars.myVar,
"b":flowVars.myVar2
}
Upvotes: 1