🌐
Oxygen XML
oxygenxml.com › doc › ug-editor › topics › convert-XML-to-JSON-x-tools.html
XML to JSON Converter
Oxygen XML Editor includes a useful and simple tool for converting XML files to JSON.
🌐
W3Schools
w3schools.com › js › js_json_xml.asp
JSON vs XML
Both JSON and XML can be fetched with an XMLHttpRequest ... XML has to be parsed with an XML parser.
People also ask

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
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
🌐
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.
🌐
Newtonsoft
newtonsoft.com › json › help › html › ConvertJsonToXml.htm
Convert JSON to XML
This sample converts JSON to XML. Sample · Usage · Copy · string json = @"{ '@Id': 1, 'Email': 'james@example.com', 'Active': true, 'CreatedDate': '2013-01-20T00:00:00Z', 'Roles': [ 'User', 'Admin' ], 'Team': { '@Id': 2, 'Name': 'Software Developers', 'Description': 'Creators of fine software products and services.'
🌐
Site24x7
site24x7.com › tools › json-to-xml.html
Json to XML Converter: Site24x7 Tools
Site24x7s JSON to XML converter converts your JSON data to its equivalent XML format. The JSON keys are converted to XML elements and JSON values are transformed into element values. The tool supports attributes in XML Element.
🌐
Teleport
goteleport.com › resources › tools › json-to-xml-converter
JSON to XML Converter | Instant JSON to XML Conversion | Teleport
For more complex tasks and integration into existing codebases, use libraries tailored to specific programming languages: Java: Jackson and Gson offer robust conversion capabilities, handling complex data structures and providing customization options. Python: xmltodict and json2xml seamlessly integrate into Python applications for efficient data transformations. # Example of using xmltodict in Python import xmltodict import json json_data = '{"key": "value"}' xml_data = xmltodict.unparse(json.loads(json_data)) print(xml_data)
🌐
Newtonsoft
newtonsoft.com › json › help › html › convertingjsonandxml.htm
Converting between JSON and XML
Json.NET supports converting JSON to XML and vice versa using the XmlNodeConverter.
🌐
JSON Formatter
jsonformatter.org › json-to-xml
Best JSON to XML Converter
It's very simple and easy way to transform and share JSON to XML data ... JSON Example with all data types including JSON Array.
Find elsewhere
🌐
Convertjson
convertjson.com › json-to-xml.htm
JSON To XML Converter
Use this tool to convert JSON into XML format. New- Now supports JSONLines. Enter your JSON or JSONLines data below and Press the Convert button. The output will display below the Convert button.
🌐
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..
🌐
Code Beautify
codebeautify.org › jsontoxml
Best JSON to XML Converter to convert JSON to XML String, File, URL
Best Online JSON to XML Converter, Transformer Online Utility. Load form URL, Download, Save and Share.
🌐
Oxygen XML
oxygenxml.com › doc › ug-editor › topics › convert-JSON-to-XML-x-tools.html
JSON to XML Converter
Oxygen XML Editor includes a useful and simple tool for converting JSON files to XML.
🌐
FreeFormatter
freeformatter.com › json-to-xml-converter.html
Free Online JSON to XML Converter - FreeFormatter.com
This free online tool lets you convert a JSON into an XML file and formats the output with your chosen indentation
Top answer
1 of 5
12

For a simple solution, I recommend Jackson, as it can transform arbitrarily complex JSON into XML with just a few simple lines of code.

import org.codehaus.jackson.map.ObjectMapper;

import com.fasterxml.jackson.xml.XmlMapper;

public class Foo
{
  public String name;
  public Bar bar;

  public static void main(String[] args) throws Exception
  {
    // JSON input: {"name":"FOO","bar":{"id":42}}
    String jsonInput = "{\"name\":\"FOO\",\"bar\":{\"id\":42}}";

    ObjectMapper jsonMapper = new ObjectMapper();
    Foo foo = jsonMapper.readValue(jsonInput, Foo.class);

    XmlMapper xmlMapper = new XmlMapper();
    System.out.println(xmlMapper.writeValueAsString(foo));
    // <Foo xmlns=""><name>FOO</name><bar><id>42</id></bar></Foo>
  }
}

class Bar
{
  public int id;
}

This demo uses Jackson 1.7.7 (the newer 1.7.8 should also work), Jackson XML Databind 0.5.3 (not yet compatible with Jackson 1.8), and Stax2 3.1.1.

2 of 5
6

Here is an example of how you can do this, generating valid XML. I also use the Jackson library in a Maven project.

Maven setup:

<!-- https://mvnrepository.com/artifact/com.fasterxml/jackson-xml-databind -->
    <dependency>
        <groupId>com.fasterxml</groupId>
        <artifactId>jackson-xml-databind</artifactId>
        <version>0.6.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.6</version>
    </dependency>

Here is some Java code that first converts a JSON string to an object and then converts the object with the XMLMapper to XML and also removes any wrong element names. The reason for replacing wrong characters in XML element names is the fact that you can use in JSON element names like $oid with characters not allowed in XML. The Jackson library does not account for that, so I ended up adding some code which removes illegal characters from element names and also the namespace declarations.

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.xml.XmlMapper;

import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Converts JSON to XML and makes sure the resulting XML 
 * does not have invalid element names.
 */
public class JsonToXMLConverter {

    private static final Pattern XML_TAG =
            Pattern.compile("(?m)(?s)(?i)(?<first><(/)?)(?<nonXml>.+?)(?<last>(/)?>)");

    private static final Pattern REMOVE_ILLEGAL_CHARS = 
            Pattern.compile("(i?)([^\\s=\"'a-zA-Z0-9._-])|(xmlns=\"[^\"]*\")");

    private ObjectMapper mapper = new ObjectMapper();

    private XmlMapper xmlMapper = new XmlMapper();

    String convertToXml(Object obj) throws IOException {
        final String s = xmlMapper.writeValueAsString(obj);
        return removeIllegalXmlChars(s);
    }

    private String removeIllegalXmlChars(String s) {
        final Matcher matcher = XML_TAG.matcher(s);
        StringBuffer sb = new StringBuffer();
        while(matcher.find()) {
            String elementName = REMOVE_ILLEGAL_CHARS.matcher(matcher.group("nonXml"))
                    .replaceAll("").trim();
            matcher.appendReplacement(sb, "${first}" + elementName + "${last}");
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    Map<String, Object> convertJson(String json) throws IOException {
        return mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
    }

    public String convertJsonToXml(String json) throws IOException {
        return convertToXml(convertJson(json));
    }
}

Here is a JUnit test for convertJsonToXml:

@Test
void convertJsonToXml() throws IOException, ParserConfigurationException, SAXException {
    try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("json/customer_sample.json")) {
        String json = new Scanner(in).useDelimiter("\\Z").next();
        String xml = converter.convertJsonToXml(json);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
        Node first = doc.getFirstChild();
        assertNotNull(first);
        assertTrue(first.getChildNodes().getLength() > 0);
    }
}
🌐
ReqBin
reqbin.com › json-to-xml
Online JSON to XML Converter
The JSON to XML converter allows you to convert JSON objects into XML data strings. The JSON converter is fully compatible with JSON and supports JSON elements, arrays, attributes, texts, comments, and JSON declarations. The JSON to XML converter produces clean and reversible XML strings; you ...
Top answer
1 of 9
13

You may take a look at the Json-lib Java library, that provides XML-to-JSON conversion.

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read( xml );  

If you need the root tag too, simply add an outer dummy tag:

CopyString xml = "<hello><test>1.2</test><test2>123</test2></hello>";
XMLSerializer xmlSerializer = new XMLSerializer();  
JSON json = xmlSerializer.read("<x>" + xml + "</x>");  
2 of 9
10

There is no direct mapping between XML and JSON; XML carries with it type information (each element has a name) as well as namespacing. Therefore, unless each JSON object has type information embedded, the conversion is going to be lossy.

But that doesn't necessarily matter. What does matter is that the consumer of the JSON knows the data contract. For example, given this XML:

Copy<books>
  <book author="Jimbo Jones" title="Bar Baz">
    <summary>Foo</summary>
  </book>
  <book title="Don't Care" author="Fake Person">
    <summary>Dummy Data</summary>
  </book>
</books>

You could convert it to this:

{
    "books": [
        { "author": "Jimbo Jones", "title": "Bar Baz", "summary": "Foo" },
        { "author": "Fake Person", "title": "Don't Care", "summary": "Dummy Data" },
    ]
}

And the consumer wouldn't need to know that each object in the books collection was a book object.

Edit:

If you have an XML Schema for the XML and are using .NET, you can generate classes from the schema using xsd.exe. Then, you could parse the source XML into objects of these classes, then use a DataContractJsonSerializer to serialize the classes as JSON.

If you don't have a schema, it will be hard getting around manually defining your JSON format yourself.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › framework › wcf › feature-details › mapping-between-json-and-xml
Mapping Between JSON and XML - WCF | Microsoft Learn
On the JSON to XML mapping, all ... of EIIs (including nesting within arrays) are allowed. Example: The following element maps to a JSON fragment....
🌐
Altova
altova.com › xmlspy-xml-editor › xml-to-json
XML to JSON Converter | Altova
You can easily convert between JSON and XML because both describe hierarchical data. Tools like Altova XMLSpy make this conversion seamless: you can open a JSON file and instantly view or transform it as XML (and vice versa) with additional support for validation, schema generation, and more.
🌐
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, we can convert a JSON string to XML using the XmlMapper class. The class has a writeValueAsString() method that takes a JsonNode as an argument and returns an XML string.
🌐
Digitaltoolpad
digitaltoolpad.com › blog › json-to-xml
Your Guide to Seamless JSON to XML Conversion - Digital ToolPad Blog
1 week ago - How it works: Let's say your JSON has {"description": "User input <example>"}. A smart converter can be configured to wrap this in <description><![CDATA[User input <example>]]></description>, keeping the data perfectly intact.