JSON to XML Converter
Convert a JSON object or array into well-formed, indented XML.
Was this tool helpful?
Thanks for the feedback!
Paste a JSON object and this converter produces indented XML, with an XML declaration at the top, everything wrapped in a <root> element, and each key turned into a child element. It helps developers who need to feed JSON data to a system that only accepts XML, such as an older SOAP service, an enterprise integration or a document template.
Example
Input:
{"user": {"name": "Asef", "age": 28, "tags": ["admin", "editor"],
"manager": null, "home city": "Pune & Mumbai"}}
Output after clicking Convert to XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<name>Asef</name>
<age>28</age>
<tags>admin</tags>
<tags>editor</tags>
<manager/>
<home_city>Pune & Mumbai</home_city>
</user>
</root>
The mapping rules
- Objects become elements containing one child element per key, indented two spaces per level.
- Arrays become repeated elements that all use the key's name, as with the two
tagselements. There is no wrapper element around the list. - Strings, numbers and booleans become the element's text, so
trueis written as the text true. - null becomes an empty self-closing element such as
<manager/>. - Special characters in text are escaped: & becomes
&, and < and > become<and>. - Key names keep letters, digits, underscores, dots and hyphens; any other character, including a space, becomes an underscore, which is why "home city" turned into
home_city. - Every value becomes an element. The converter never produces XML attributes.
Inputs that give invalid XML
A top-level array
If the JSON starts with [, each array item becomes its own <root> element, one after another. An XML document may have only one root element, so strict parsers will reject the result. Wrap the array in an object first: {"item": [ ... ]} gives a single root with repeated <item> children.
Keys that start with a digit
XML element names cannot begin with a number, but a key such as "2024" is passed through as <2024>. Rename those keys, for example to year_2024, before converting.
Empty arrays and objects
An empty array produces no element at all, and an empty object produces an opening and closing tag with blank lines between them. If the receiving system expects the element to exist, add it by hand.
Before sending the XML on
Most XML consumers validate against a schema (XSD) that fixes element names, order and sometimes a namespace. The converter keeps your JSON key order and adds no namespace, so compare the output with a sample of what the system expects and rename root if needed. Invalid JSON is reported with the parser's error message; check it in the JSON Validator first. To reformat or inspect the XML afterwards, use the XML Formatter, and for the reverse direction there is the XML to JSON Converter.