I am trying to transform a JSON object to an XML object using Mule Dataweave
. Below is the input JSON:
{
"root": {
"OBJECT1": {
"PARAM1": "PARAM1VALUE",
"PARAM2": "PARAM2VALUE"
},
"OBJECT2": [{
"KEY": "PARAMROWKEYVALUE1",
"VALUE": "PARAMROWVALUEVAL1"
}, {
"KEY": "PARAMROWKEYVALUE2",
"VALUE": "PARAMROWVALUEVAL2"
}],
"OBJECT3": {
"PARAM3": "PARAM3VALUE",
"PARAM4": "PARAM4VALUE"
}
}
}
I want to transform the above to the XML below:
<root>
<node1>PARAM1VALUE PARAM2VALUE</node1>
<args>
<paramrow>
<KEY>PARAMROWKEYVALUE1</KEY>
<VALUE>PARAMROWVALUEVAL1</VALUE>
</paramrow>
<paramrow>
<KEY>PARAMROWKEYVALUE2</KEY>
<VALUE>PARAMROWVALUEVAL2</VALUE>
</paramrow>
</args>
<details>
<PARAM3>PARAM3VALUE</PARAM3>
</details>
</root>
But, when I used this JSON as sample input, it throws an error saying "validate mapping":
%dw 1.0
%output application/xml
---
payload
How do I map these object elements to XML?