Skip to content
codevory

JSON to XML Converter

Convert JSON to well-formed XML with a root element you choose. Arrays repeat their element, and invalid names are repaired and reported.

JSON to XML Converter: the tool

Paste JSON to convert it to XML.

Input

XML

The result appears here.

How to use JSON to XML

  1. Paste JSON into the left panel, or press Example.
  2. Set the root element name, which wraps the whole document, and the name used for array items that have no key.
  3. Choose the indentation or Minified, and whether to include the <?xml ...?> declaration.
  4. Copy the XML or download it as a .xml file. A warning lists any key that had to be renamed.

Example

An object with a nested object, an array, a boolean and a null. The array repeats the tags element.

JSON
{"name":"Ada","age":36,"admin":true,"note":null,"tags":["math","code"],"address":{"city":"London"}}
XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>Ada</name>
  <age>36</age>
  <admin>true</admin>
  <note/>
  <tags>math</tags>
  <tags>code</tags>
  <address>
    <city>London</city>
  </address>
</root>

About this tool

JSON and XML do not map onto each other one to one, so converters follow conventions. Here an object becomes child elements named after its keys, and an array under a key repeats an element with that key's name, one per item. A top-level array, or an array inside an array, uses the Array item name instead. Strings, numbers and booleans become the text of an element, and null and empty strings become an empty element.

XML names are stricter than JSON keys. They must start with a letter or underscore and cannot contain spaces or most punctuation. A key such as first name is written as first_name, and 1st as _1st. Each repair is listed as a warning so that nothing changes silently. Text is escaped (&, < and >), and control characters that XML 1.0 cannot carry are removed with a warning.

The result is always well-formed, and the tool uses the same XML checker as the XML formatter. There is no attribute syntax: every JSON key becomes an element. If you need attributes, convert first and adjust the result.

Conversion rules

JSONXML
{"a": 1}<a>1</a> inside the root element
{"a": [1, 2]}<a>1</a><a>2</a> (one element per item)
{"a": null} or {"a": ""}<a/> (an empty element)
[1, 2] at the top level<root><item>1</item><item>2</item></root>
{"first name": 1}<first_name>1</first_name> plus a warning
{"a": "x < y"}<a>x &lt; y</a>

Frequently asked questions

Why does the XML have a root element I did not have in my JSON?

An XML document must have exactly one root element, and a JSON object or array has no name to use. The root element name option supplies it, and you can change it to whatever your consumer expects.

Can I produce XML attributes?

No. Every JSON key becomes a child element, because there is no standard way to mark a key as an attribute. Edit the result if you need attributes.

What happens to keys that are not valid XML names?

They are repaired by replacing invalid characters with underscores and adding a leading underscore when needed. Each repair is shown as a warning with the original and the new name.

Is null different from an empty string in the result?

No. Both become an empty element, because XML has no null value. If you must tell them apart, use a different convention in your data.

Is the output guaranteed to be valid XML?

Yes for syntax: names are valid, text is escaped and unsupported control characters are removed. It is not validated against any schema.