DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Loading XML into MongoDB
  • Validate XML Request Against XML Schema in Mule 4
  • How to Convert JSON to XML or XML to JSON in Java
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps

Trending

  • Stop Using Python for Your GenAI Apps, Use Go and Genkit Instead
  • We Went Multi-Cloud and Almost Drowned: Lessons From Running Across AWS, GCP, and Azure
  • Why AI Forces a Rethink of Everything We Know About Software Security
  • Comparing Top Gen AI Frameworks for Java in 2026
  1. DZone
  2. Coding
  3. Languages
  4. JSON to XML Transformation Using DataWeave 2.0 in Mule 4.0

JSON to XML Transformation Using DataWeave 2.0 in Mule 4.0

This post will explain the simple way to do a JSON to XML transformation in MuleSoft by using DataWeave.

By 
Ramesh Mandali user avatar
Ramesh Mandali
·
Aug. 08, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
22.8K Views

Join the DZone community and get the full member experience.

Join For Free

Nowadays, most of the data would be like JSON or XML as the input/output to every system. To get the required format for downstream system bit complex to transform but MuleSoft will do that easily and push into the target system. This post will explain the simple way to do a JSON to XML transformation in MuleSoft. This can be done by using DataWeave, and not only JSON, but others like Java, CSV, and XML format.

Step1: Select the Mule project from Anypoint Studio and write the project name. Then, click ok.

Step2: Drag and drop HTTP listener, and transform the message to track the logs logger component from Mule palette.

Step3: Load the metadata and map the data as shown in the below screenshot.

Step4: After that, you can deploy your application by right clicking on the flow and running the project databaseSelect. Then you will see the DEPLOYED status in the console.

Step5: Check that your application is running as expected from Postman.

Code snippet:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"

       xmlns="http://www.mulesoft.org/schema/mule/core"

   xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd

http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd

http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="8f99e5e7-3375-46e5-ad5e-23b6c4d9624c" >

             <http:listener-connection host="0.0.0.0" port="6757" />

       </http:listener-config>

       <flow name="jsontoxmlFlow" doc:id="37c1e6ab-60f2-423e-9f95-a1c6417844da" >

             <http:listener doc:name="Listener" doc:id="64cb15b9-06d1-4e9a-8b79-8adca4ca1892" config-ref="HTTP_Listener_config" path="/jsontoxml">

                    <ee:repeatable-file-store-stream />

             </http:listener>

             <ee:transform doc:name="Transform Message" doc:id="5cf58b0e-23ad-4925-a763-88bc7a906349" >

                    <ee:message >

                          <ee:set-payload ><![CDATA[%dw 2.0

output application/xml

---

{

       test:payload

}]]></ee:set-payload>

                    </ee:message>

             </ee:transform>

             <logger level="INFO" doc:name="Logger" doc:id="6f05b849-991d-4034-9e5d-4f6751fdd030" message="Success: #[payload] "/>

       </flow>

</mule>

Thank you.

JSON XML

Opinions expressed by DZone contributors are their own.

Related

  • Loading XML into MongoDB
  • Validate XML Request Against XML Schema in Mule 4
  • How to Convert JSON to XML or XML to JSON in Java
  • How to Connect to Splunk Through Anypoint Studio in 10 Steps

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook