Convert file XML to JSON in Java using REST API

How to Convert XML to JSON in Java using REST API.

As the world becomes more connected and technology more advanced, the exchange of data between systems and applications has become increasingly important. One common way to represent data is through XML (eXtensible Markup Language). However, JSON (JavaScript Object Notation) has become the preferred format for exchanging data between systems due to its simplicity and flexibility. In this article, we will demonstrate how to convert XML to JSON in Java using REST API.

We will cover the following topics in this article:

Java XML to JSON Converter API and SDK Installation

GroupDocs.Conversion Cloud SDK for Java is a cloud-based document conversion solution that helps Java developers to convert various document formats to JSON in Java. It allows you to convert documents, images, spreadsheets, presentations, and many other file types to JSON with just a few lines of code. This RESTful API can be integrated into your Java applications to provide a fast and reliable conversion solution.

You can either download the API’s JAR file or install it using Maven by adding the following repository and dependency into your project’s pom.xml file:

Maven Repository:

    <name>GroupDocs Artifact Repository</name>

Maven Dependency:


Now, sign up for a free trial account on GroupDocs and get your API key. Once you have the Client Id and Client Secret, add below code snippet to a Java-based application:

How to Convert XML File into JSON in Java using REST API

Here is a step-by-step guide on how to convert XML to JSON programmatically in Java using GroupDocs.Conversion Cloud SDK for Java:

Upload the File

Firstly, upload the XML file to the cloud using the code snippet given below:

As a result, the uploaded XML file will be available in the files section of your dashboard on the cloud.

Convert XML to JSON with Java

In this section, we will cover the steps and the code snippet to convert an XML file to a JSON file format programmatically in Java.

  • Firstly, import the required classes into your Java file.
  • Secondly, create an instance of the ConvertApi class.
  • Thirdly, create an instance of ConvertSettings class.
  • After that, provide your cloud storage name.
  • Now, set the source file path and the target format to “json”.
  • Next, set the output file path.
  • Then, create the ConvertDocumentRequest class instance and pass the settings parameter.
  • Lastly, convert XML to JSON by calling the convertDocument() method and passing the ConvertDocumentRequest parameter.

Below code snippet shows how to convert XML file to JSON schema in Java using REST API. Copy & paste the following code into your Java application:

Download the Converted File

The above code sample will save the converted JSON file in the cloud. You can download it using the following code sample:

Free Online XML to JSON Converter

How to convert XML to JSON online for free? Please try the following online XML to JSON converter for free. This converter is developed using the above-mentioned GroupDocs.Conversion Cloud REST API.


In conclusion, data conversion is an important task for any software developer, and the GroupDocs.Conversion Cloud SDK for Java makes it easy to handle different data formats with ease. The following is what you have learned from this article:

  • how to convert XML to JSON file programmatically in Java;
  • programmatically upload XML files and then download the converted JSON file from the cloud;
  • and convert any XML file to JSON for free using a free online XML to JSON converter.

Moreover, we also provide an API Reference section that lets you visualize and communicate with our APIs directly through the browser. Java SDK’s complete source code is freely available on Github. Please check the GroupDocs.Conversion Cloud SDK for Java Examples here.

Additionally, we suggest you follow our Getting Started guide for detailed steps and API usage.

Finally, we keep writing new blog articles on different file formats and conversions using REST API. So, please get in touch for the regular updates.

Ask a question

You can ask your queries about XML to JSON converter API, via our forum.


How do I convert an XML to a JSON file online for free?

Please follow the step-by-step instructions to convert an XML file to JSON online for free:

  • Open online XML to JSON converter.
  • Now, click inside the file drop area to upload an XML file or drag & drop an XML file.
  • Next, click on the Convert Now button. Online XML to JSON converter will change XML into a JSON file.
  • The download link of the output file will be available instantly after conversion.

How to convert XML to JSON on Windows?

Please visit the download link to download the XML to JSON offline converter for Windows. This free XML to JSON converter can be used to convert XML documents to JSON files on Windows quickly, with a single click.

What are some other file formats that the GroupDocs.Conversion Cloud SDK for Java supports?

The SDK supports a wide range of file formats, including PDF, DOCX, XLSX, PPTX, HTML, CSV, and many more.

See Also

If you want to learn more about related topics, we recommend reading the articles listed below: