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

  • 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

  • Building a Software Factory With AI Agents and Workflows
  • AI-Era Cybersecurity, Part 1: Mapping Glasswing, Daybreak, Lightwell and the Tools Racing to Find and Fix Bugs
  • AI Coding Agent Guardrails: Finding Gaps in Tool Permissions
  • When One Docker Swarm Replica Became Unreachable Over an Overlay Network: A Production Case With Traefik

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. MuleSoft 4.0 BETA (XML to JSON Transformation)

MuleSoft 4.0 BETA (XML to JSON Transformation)

This tutorial explains how to transform XML to JSON.

By 
Varun Goyal
·
Jul. 02, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
16.0K 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

Step 1

Open Anypoint studio and create a new project as shown namely as xml2json.

  • Drag and drop an HTTP listener Connector to get a request for your servers and give the host and port numbers. Like here, the host is set to mule4.eaiesb.com and port to 8099 and test your connection to check whether the port is in use or not by testing the connection successfully.
  • After the successful connection and verification that the port is not reserved, set the path for your service as: /xml2json

Step 2

Drag a transform message from the Mule palette.

  • It helps us to transform the Mule message from the XML to JSON as shown:

Image title

Step 3

Set the input metadata and output metadata format.

  • Click on +Add to select the input XML schema file and give a friendly name like StudentsXMLSchema.
  • Select the type as XML and from Schema, select an input file as here: Students.xsd as shown below:

Image title

  • Set the output metadata and Type ID: StudentsJSONSchema is used as the name by selecting Type as JSON and set the Schema as here: Students.json and create the desired output structure as shown:

Image title

Step 4

Map input metadata fields to output fields.

  • Once you map the field, the transform message will write the code with respect accordingly to that shown below:

Image title

Step 5

Run the Mule project.

By default, Mule will download all the artifacts from the Maven repository and once the project does not have errors, it will show a successful deployment.

Step 6

Open the Postman and hit the service URL request as shown:

  • Select the method as POST and go to body and select raw in it. Select the DataType as XML and give the XML data in body and click on Send.

Image title


Step 7

Check the output response data in the JSON format transformed successfully.

Image title

Happy Learning!!

XML JSON BETA (programming language) 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

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