How to convert JSON to XML
- Paste JSON or open a file. The XML updates as you type.
- Set Root (default
root), switch XML declaration on or off, and pick the Indent. - Press ⇄ to check the round trip in XML to JSON.
Invalid JSON stops with the line and column of the mistake. JSON repair removes comments and trailing commas in one click; common JSON errors covers the rest.
Example
{
"invoice": {
"@number": "INV-77",
"customer": "Kai Tanaka",
"lines": [
{ "item": "Hosting", "amount": 20 },
{ "item": "Domain", "amount": 12 }
],
"2fa enabled": true,
"notes": null
}
}
<?xml version="1.0" encoding="UTF-8"?>
<invoice number="INV-77">
<customer>Kai Tanaka</customer>
<lines>
<item>Hosting</item>
<amount>20</amount>
</lines>
<lines>
<item>Domain</item>
<amount>12</amount>
</lines>
<_2fa_enabled>true</_2fa_enabled>
<notes/>
</invoice>
The note under the output lists 2fa enabled as renamed.
How the mapping works
- Root. An object with a single key, like
invoice, uses that key as the root and ignores Root. Several top-level keys, a top-level array or a lone value are wrapped in the Root name; array items become<item>elements. - Attributes and text.
@numberbecamenumber="INV-77", and a#textkey becomes the element’s text, matching what XML to JSON produces. - Arrays. Each item becomes an element named after the key, so
<lines>appears twice. For a wrapper, nest it:{"lines": {"line": [...]}}gives one<lines>with two<line>children. An empty array becomes an empty element such as<tags/>, and an array inside an array is wrapped in<item>elements. - Empty values.
nulland{}become an empty element such as<notes/>. - Names. A name cannot start with a digit or contain spaces, so
2fa enabledbecame_2fa_enabled; symbols such as$and/also become_. - Escaping.
<,&and"in values are written as<,&and".