๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ json-to-xml
Best JSON to XML Converter
JSON to XML is very unique tool for convert JOSN to XML and allows to download, save, share and print JSON to XML data..
๐ŸŒ
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.
๐ŸŒ
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..
๐ŸŒ
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.
๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ json to xml converter
JSON to XML Converter
Convert JSON text into XML format online, save the output to a file or copy and paste into your projects. Free to use online tool, quickly convert any JSON file or text.
๐ŸŒ
Online XML Tools
onlinexmltools.com โ€บ convert-json-to-xml
Convert JSON to XML - Online XML Tools
Free online JSON to XML converter. Just paste your JSON in the input form below and it will automatically get converted to XML. There are no ads, popups or nonsense, just an awesome JSON to XML transformer. Load JSON, get XML.
๐ŸŒ
JSON Formatter
jsonformatter.org
Best JSON Formatter and JSON Validator: Online JSON Formatter
Online JSON Formatter / Beautifier and JSON Validator will format JSON data, and helps to validate, convert JSON to XML, JSON to CSV. Save and Share JSON
Find elsewhere
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.
๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-formatter
Best XML Formatter and XML Beautifier
Online XML Formatter will format xml data, helps to validate, and works as XML Converter. Save and Share XML.
๐ŸŒ
cbaTool
cbatool.com โ€บ home โ€บ converters โ€บ json to xml formatter online: change json to xml & xml from json
JSON to XML Formatter Online: Change JSON to XML & XML from JSON - cbaTool
January 19, 2026 - Whether youโ€™re working with simple JSON objects, nested arrays, or large JSON datasets, this tool preserves your original data structure while formatting the output XML for readability and compatibility with all XML parsers and applications. You can paste JSON code directly or upload files for batch conversionโ€”all processing is done locally in your browser, with no sign-ups, installations, or hidden fees.
๐ŸŒ
Community
community.safe.com โ€บ transformers-9 โ€บ storing-json-format-into-xml-20003
Storing json format into XML | Community
November 16, 2022 - Send the JSON document through an TextEncoder set to XML encoding before using it in the XMLTemplater (it'll look like the example you don't like above), or ยท Put the JSON document in a CDATA section in the XML, https://www.w3.org/TR/REC-x...
๐ŸŒ
Utilities and Tools
utilities-online.info โ€บ xmltojson
XML to JSON & JSON to XML converter online
Write or paste XML code in the left input box. Click the Right Arrow button. You can also convert your JSON code to XML by using our JSON to XML converter.
๐ŸŒ
JSON Formatter
jsonformatter.net โ€บ home โ€บ json to xml converter
JSON to XML Converter: Convert JSON to XML
February 9, 2023 - JSON to XML: Convert JSON to XML with our easy-to-use JSON to XML converter. This JSON to XML converter automatically converts your JSON to XML instantly. Simply paste your JSON code or upload JSON file then click on the โ€œJSON to XMLโ€ button.