How to Convert JSON to XML
Some systems — SOAP services, legacy APIs, certain config formats — still expect XML. Converting JSON to XML is straightforward once you know how the two structures line up.
How JSON maps to XML
Object keys become elements, and scalar values become the text inside them:
{ "note": { "to": "Dev", "body": "Convert me" } }
<?xml version="1.0" encoding="UTF-8"?>
<root>
<note>
<to>Dev</to>
<body>Convert me</body>
</note>
</root>
Everything is wrapped in a single <root> element because XML documents must have exactly one root.
How arrays are handled
XML has no array type, so a JSON array is written as a repeated element — the same tag once per item:
{ "tags": ["fast", "free"] }
<tags>fast</tags>
<tags>free</tags>
A top-level array is a special case: since there's no key to name the elements, it's wrapped in <root> and each entry becomes an <item>.
Escaping and key names
Two things happen automatically to keep the XML well-formed:
- Special characters (
<,>,&) in values are escaped to<,>, and&. - Invalid element names — keys with spaces or symbols, or starting with a digit — are sanitized (invalid characters become
_), since XML element names have stricter rules than JSON keys.
The other direction
Need to go back? See How to Convert XML to JSON, and for choosing between formats, JSON vs XML vs YAML vs CSV.
Try it
Paste JSON and get clean, indented XML instantly — everything runs in your browser, nothing uploaded.