Convert JSON to XML in your browser
Legacy APIs, SOAP payloads and many config formats still expect XML, but modern data is usually JSON. This converter turns any valid JSON object or array into well-formed XML with consistent two-space indentation, so the result is always valid and ready to use.
How it works
The converter walks the JSON and maps each construct to XML:
- Objects become nested elements, one per key.
- Arrays repeat their parent element once per item — the standard lossless
convention — so
"tags": ["a","b"]becomes<tags>a</tags><tags>b</tags>. - A single
<root>element wraps the whole document so it is always well-formed. - Escaping: the
&,<and>characters in text are escaped, and property names that aren’t legal XML element names are sanitised. - Null has no XML equivalent, so it is emitted as an empty element.
Example
This JSON:
{ "name": "demo", "tags": ["a", "b"] }
becomes:
<root>
<name>demo</name>
<tags>a</tags>
<tags>b</tags>
</root>
The tags array repeated the <tags> element once per item, and <root> wraps
the document. The conversion happens entirely in your browser — your data is
never uploaded or stored.
A more complete worked example
JSON:
{
"order": {
"id": "ORD-001",
"customer": "Alice",
"items": [
{ "sku": "W-01", "qty": 2 },
{ "sku": "W-02", "qty": 1 }
],
"shipped": null
}
}
XML output:
<root>
<order>
<id>ORD-001</id>
<customer>Alice</customer>
<items>
<sku>W-01</sku>
<qty>2</qty>
</items>
<items>
<sku>W-02</sku>
<qty>1</qty>
</items>
<shipped></shipped>
</order>
</root>
Each items entry repeats the <items> tag; the null value becomes an empty <shipped/> element.
Key XML escaping rules
JSON values can contain characters that are not valid as raw XML content:
| Character | JSON | XML escaped form |
|---|---|---|
| Ampersand | & | & |
| Less-than | < | < |
| Greater-than | > | > |
| Double quote (in attributes) | " | " |
The converter handles all of these automatically. If your JSON values contain HTML snippets or URLs with ampersands, the output is safe XML.
Element name rules
XML element names cannot start with a digit or contain spaces. If a JSON key violates these rules (for example "1stItem" or "full name"), the converter sanitises it — prepending an underscore for names starting with a digit, and replacing spaces with underscores — so the output is always a well-formed XML document.