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

  • Anypoint Mulesoft Masking Sensitive Data With DataWeave Custom Function in Logging
  • Loading XML into MongoDB
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Validate XML Request Against XML Schema in Mule 4

Trending

  • How to Format Articles for DZone
  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • Lambda-Driven API Design: Building Composable Node.js Endpoints With Functional Primitives
  • AI Paradigm Shift: Analytics Without SQL
  1. DZone
  2. Coding
  3. Languages
  4. XML to JSON Conversion in MuleSoft

XML to JSON Conversion in MuleSoft

If you need to perform an XML to JSON conversion, MuleSoft is the way to go. It offers multiple ways to perform this transformation.

By 
Rakesh Kumar Jha user avatar
Rakesh Kumar Jha
·
Feb. 11, 17 · Opinion
Likes (5)
Comment
Save
Tweet
Share
20.1K Views

Join the DZone community and get the full member experience.

Join For Free

MuleSoft supports XML to JSON transformations in multiple ways. Below are two similar ways to do this, along with solutions to overcome the problems in them.

1. Direct Conversion

Mule provides XML to JSON transformer activity that can directly convert an XML input into a JSON object. Below is the syntax that is generated when you drag an XML to JSON transformer from the Mule palette to the Mule flows.

<json:xml-to-json-transformer doc:name="XML to JSON"/>

The problem with the above approach is in dealing with repetitive elements inside the XML. This transformer doesn't really work when the repetitive XML element comes only once in the input payload. 

2. Conversion With DataWeave

Mule DataWeave also provides XML to JSON conversion in multiple ways. The easiest way to convert XML to JSON is to simply write PAYLOAD into DataWeave.

This approach also leads to a problem in dealing with repetitive elements inside the XML. Like in the first example, the transformer doesn't really work when the repetitive XML element comes only once in the input payload.  

The above problems can be resolved by defining both the input XML structure and the output JSON structure in the DataWeave transformation.

XML JSON MuleSoft

Opinions expressed by DZone contributors are their own.

Related

  • Anypoint Mulesoft Masking Sensitive Data With DataWeave Custom Function in Logging
  • Loading XML into MongoDB
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Validate XML Request Against XML Schema in Mule 4

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