MuleSoft 4.0 BETA (XML to JSON Transformation)

DZone 's Guide to

MuleSoft 4.0 BETA (XML to JSON Transformation)

This tutorial explains how to transform XML to JSON.

· Integration Zone ·
Free Resource

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

mule ,xml to json ,http ,mulesoft ,connectors

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}