Javatpoint Logo
Javatpoint Logo

Convert JSON to XML in Java

JSON is a very light weighted data interchange format that stores data in a key-value pair. In this section, we understand how we can convert JSON data to XML or XML data to JSON.

Many times, we can come across a situation where we need to convert JSON to XML or vice versa. By using the org.json.XML class, we can easily convert JSON objects into XML data or XML data into JSON data. The org.json.XML class provides methods that help us in the conversion of different formats.

The XML.toString() method of the org.json.XML class plays an important role in converting JSON objects into an XML string.

The syntax of the toString() method of the org.json.XML is as follows:

Let's take examples of both of them and understand how the toString() method works in the conversion of different data interchange formats.

ConvertJsonToXml.java

Output:

Convert JSON to XML in Java
Convert JSON to XML in Java

ConvertXmlToJson.java

Output:

Convert JSON to XML in Java
Convert JSON to XML in Java





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA