JSON to XML Converter
Map a JSON document onto an XML tree, with control over the root element, array handling and indentation.
Your data stays on your device
Input — JSON
- characters
- 0
- lines
- 0
- size
- 0 B
Output — XML
- characters
- 0
- lines
- 0
- size
- 0 B
Options
XML needs exactly one root element, which JSON does not provide.
About this tool
JSON and XML describe the same kind of hierarchical data with different assumptions. JSON has native arrays and a small set of scalar types; XML has elements, attributes and text nodes but no concept of an array. Converting between them therefore requires decisions, not just a translation table.
This converter takes the conventional approach: each object key becomes an element, each array becomes that element repeated once per item, and scalars become escaped text content. You choose the root element name and whether to emit an XML declaration.
How to use this tool
- Paste JSON on the left or upload a .json file.
- Set the root element name — XML requires exactly one root, which JSON does not provide.
- Choose whether to pretty-print and whether to include the <?xml ... ?> declaration.
- Press Convert, then copy the XML or download it as .xml.
Key features
- Configurable root element name
- Arrays expanded into repeated sibling elements
- Automatic escaping of &, <, >, " and ' in text content
- Optional XML declaration with UTF-8 encoding
- Pretty-printed or compact output
- Keys that are not valid XML names are sanitised into legal element names
Example
Input — JSON
{"book":{"title":"Deep Work","tag":["focus","habits"]}}Output — XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<book>
<title>Deep Work</title>
<tag>focus</tag>
<tag>habits</tag>
</book>
</root>Good to know
- JSON has no attributes, so every value becomes element text. Round-tripping XML that used attributes will not restore them.
- Empty arrays disappear, because there is no element to repeat. An empty object becomes an empty element.
- Keys starting with a digit or containing spaces are rewritten to satisfy XML naming rules; the original key is not recoverable from the output alone.
Frequently asked questions
Why do I have to name a root element?
An XML document must have exactly one top-level element. A JSON document can be an array or even a bare scalar, so the converter needs a name to wrap the content in.
How are arrays represented?
By repeating the parent element once per item. The array ["a","b"] under the key tag becomes two <tag> elements. That is the standard convention and is what most XML parsers expect.
What happens to null values?
They become empty elements. XML has no null, so the distinction between null and an empty string is lost in the output.
Is the output guaranteed to parse?
Yes. Special characters are escaped and element names are sanitised, so the result is well-formed XML even if the input contained characters XML reserves.
Your data stays on your device
Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.