JSON in Java has some great resources.

Maven dependency:

<dependency>
  <groupId>org.json</groupId>
  <artifactId>json</artifactId>
  <version>20180813</version>
</dependency>

XML.java is the class you're looking for:

import org.json.JSONObject;
import org.json.XML;
import org.json.JSONException;

public class Main {

    public static int PRETTY_PRINT_INDENT_FACTOR = 4;
    public static String TEST_XML_STRING =
        "<?xml version=\"1.0\" ?><test attrib=\"moretest\">Turn this to JSON</test>";

    public static void main(String[] args) {
        try {
            JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
            String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
            System.out.println(jsonPrettyPrintString);
        } catch (JSONException je) {
            System.out.println(je.toString());
        }
    }
}

Output is:

{"test": {
    "attrib": "moretest",
    "content": "Turn this to JSON"
}}
Answer from danieltalsky on Stack Overflow
🌐
Baeldung
baeldung.com › home › json › jackson › convert xml to json using jackson
Convert XML to JSON Using Jackson | Baeldung
January 8, 2024 - Jackson and JSON in Java, finally learn with a coding-first approach: >> Download the eBook · In this tutorial, we’ll see how to convert an XML message to JSON using Jackson. For readers new to Jackson, consider getting familiar with the basics first. We can think about parsing JSON in three different ways with Jackson: The first and most common is data binding with ObjectMapper ·
Discussions

Converting JSON to XML in Java - Stack Overflow
I guess the only way will be to deserialize the JSON to a (custom) Java Object. Then, using a framework like XMLBeans or XStream and with the help of annotations, specify which property goes as element and which goes as attribute 2013-11-14T14:27:40.423Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
Convert XML to JSON - Help - Enonic Discuss
I have some Data in xml-forma and would like to bootstrap my project with this data. What is best/easiest to convert from xml to json-object? I tried some Javascript based libraries, but he most of them failed, because Nashorn does not support all of the features these libs use. Is there already ... More on discuss.enonic.com
🌐 discuss.enonic.com
0
March 2, 2022
How to convert JSON to XML
Hello, I’m trying to do this: connect to an API get a JSON response with product information convert JSON into XML connect to SFTP upload a file in XML format I’ve done everything but I have no clue how to convert JSON into XML so at the moment i’m creating a file with JSON inside of it. More on community.make.com
🌐 community.make.com
1
0
January 24, 2023
Json to Xml transformation
Not sure if I understood your problem correctly. But if it’s only a meter from converting from PascalCase to camelCase, you could write a function that parses the json object and return the keys converted. More on reddit.com
🌐 r/typescript
6
3
September 28, 2022
People also ask

How do I convert XML to JSON using Python?
To convert XML to JSON using Python, you can use libraries like ‘xmltodict’ and ‘json’. First, parse the XML using ‘xmltodict.parse()’, then convert the resulting dictionary to JSON using ‘json.dumps()’. This method ensures a smooth transition from XML to JSON format while maintaining data integrity.
🌐
integrate.io
integrate.io › home › blog › conversions › how to convert xml to json: a step-by-step guide
How to Convert XML to JSON: A Step-by-Step Guide | Integrate.io
Can I convert complex XML structures to JSON seamlessly?
Converting complex XML structures to JSON can be challenging due to nested elements and attributes. However, with the right tools and careful handling, it is possible to achieve a seamless conversion. Tools like ‘xmltodict’ in Python can help manage these complexities by correctly mapping XML elements to JSON objects and arrays.
🌐
integrate.io
integrate.io › home › blog › conversions › how to convert xml to json: a step-by-step guide
How to Convert XML to JSON: A Step-by-Step Guide | Integrate.io
What are the advantages of using JSON over XML?
JSON offers several advantages over XML, including a more compact and readable format, faster parsing and generation, and better performance in web applications. JSON's structure, which uses key-value pairs and arrays, makes it easier to work with in modern programming environments and facilitates efficient data interchange.
🌐
integrate.io
integrate.io › home › blog › conversions › how to convert xml to json: a step-by-step guide
How to Convert XML to JSON: A Step-by-Step Guide | Integrate.io
🌐
InterSystems
community.intersystems.com › post › convert-xml-json
Convert XML to JSON | InterSystems Developer Community | Java|JSON|XML
So i decided to convert XML to JSON and parse json easily · So for that i wrote code in java which convert xml to json and build package with maven
🌐
HowToDoInJava
howtodoinjava.com › home › jackson › jackson – converting between xml and json
Jackson - Converting between XML and JSON
August 30, 2022 - Learn to convert between JSON and XML strings using Jackson's JsonMapper and XmlMapper using simple POJO, JsonNode and ObjectNode classes.
Find elsewhere
🌐
Integrate.io
integrate.io › home › blog › conversions › how to convert xml to json: a step-by-step guide
How to Convert XML to JSON: A Step-by-Step Guide | Integrate.io
July 21, 2025 - This blog post details the step-by-step process of converting XML to JSON. Learn essential concepts, expert tips, and strategies through clear instructions and guidance for an effective conversion.
🌐
JSON Formatter
jsonformatter.org › xml-to-json
Best XML to JSON Converter Online
XML to JSON is very unique tool for convert JOSN to XML and allows to download, save, share and print XML to JSON data..
🌐
Broadcom Community
community.broadcom.com › communities › community-home › digestviewer › viewthread
How to simply convert XML into JSON, validating JSON Schema ? | Layer7 API Management
Hi dear CA community, I have recurrent problems when converting XML into JSON. Indeed, I often get a JSON Schema of the response from my consumers, and hit an X
🌐
Quora
quora.com › How-can-I-convert-XML-to-JSON-in-Java
How to convert XML to JSON in Java - Quora
Answer (1 of 3): *If you are converting this in a mmaven project add the org.json dependency to your pom.xml. ** You can add Jackson jars too your Java project to perform this conversion. Hope the above points helped you.
🌐
Baeldung
baeldung.com › home › json › converting json to xml in java
Converting JSON to XML in Java | Baeldung
June 20, 2025 - As we can see, the output XML string is now formatted, has an XML declaration, and the root tag is root. Underscore-java is a utility library that provides methods to convert JSON to XML.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › servicenow-learning-19-convert-xml-object-to-json-in-rest-api › m-p › 2639845
ServiceNow Learning#19: Convert XML Object to JSON... - ServiceNow Community
August 11, 2023 - Hi All, It's a very common example that how we can convert our XML Response to JSON while calling REST API. Below is the live example of this scenario: function doIt() { var request = new sn_ws.RESTMessageV2(); request.setEndpoint('https://instance.service-now.com/api/now/table/incide...
🌐
TutorialsPoint
tutorialspoint.com › convert-a-json-object-to-xml-format-in-java
Convert a JSON object to XML format in Java?
April 21, 2025 - In this article, we will learn how to convert a JSON object into XML format in Java. But first, let’s understand what JSON and XML are. JSON is a lightweight data-interchange format, and the format of JSON is like a key-value pair. XML (Extensible M
🌐
Enonic Discuss
discuss.enonic.com › help
Convert XML to JSON - Help - Enonic Discuss
March 2, 2022 - I have some Data in xml-forma and would like to bootstrap my project with this data. What is best/easiest to convert from xml to json-object? I tried some Javascript based libraries, but he most of them failed, because Nashorn does not support all of the features these libs use. Is there already ...
🌐
GitHub
github.com › mohapatra-sambit › xml-to-json-converter
GitHub - mohapatra-sambit/xml-to-json-converter: Java-based XML to JSON Converter – A Generic and Flexible Tool for Converting XML Data into JSON Format with Ease
The XML to JSON Converter is a flexible java-based tool/library designed to convert any XML input into JSON format. This offers a generic tool for converting XML files into JSON format, providing flexibility for various use cases.
Author   mohapatra-sambit
🌐
InterSystems
community.intersystems.com › post › json-xml
JSON to XML | InterSystems Developer Community
A two step conversion which will require a little more coding, but will enable you to control your XML output exactly as you want it. First you will need to convert the JSON into an internal object. If you are on 2016.1 or greater then please take a look at this article... https://community.intersystems.com/post/introducing-new-json-capabiliti…
🌐
DZone
dzone.com › coding › languages › how to convert json to xml or xml to json in java
Convert JSON to XML or XML to JSON in Java
June 24, 2021 - JSON Object – the JSON object you wish to convert. API Key – your personal API key. If you need to obtain a personal API key, you can do so by register for a free account on the Cloudmersive website; this will provide 800 monthly calls across any of our APIs. Alternatively, if you need to convert XML to JSON, you simply need to input your target XML file and API key into the following code:
🌐
Leapcell
leapcell.io › blog › how-to-convert-json-to-xml-a-comprehensive-guide
How to Convert JSON to XML: A Comprehensive Guide | Leapcell
July 25, 2025 - Yes, online tools like Site24x7 or JSON Formatter allow code-free conversion. Java, JavaScript, and .NET all support conversion using libraries like Jackson, xml-js, and Json.NET.