DataWeave – Easy transformations
The DataWeave makes it easy to transform the payload into different types. But there are also some catches which you need to be aware of. In this short post, I will present how can you transform a JSON payload to XML.
XML Root Element
Some types of transformations can be applied directly, only by changing the type declaration (application/json, application/java). This is not the case for application/xml. If you have a JSON input payload you will have to add the XML root element to the DataWeave transformation.
%dw 2.0
output application/xml
---
yourRoot:
firstParam: "Your Custom Param"
XML allows only one root element.
Photo by Scott Webb on Unsplash
Hi. You can use a free online tool to convert JSON to XML https://freetools.site/data-converters/json-to-xml