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
Newsletter
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

  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL
  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard
  • Grounding AI Agents in Governed Data
  • Nobody Designs an RBAC Mess; Everyone Ends Up With One

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Aug. 08, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
22.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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