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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

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

  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • Navigating Double and Triple Extortion Tactics
  • Simplifying Multi-LLM Integration With KubeMQ
  • Designing for Sustainability: The Rise of Green Software
  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.4K 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
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!