JSON to XML converter
Paste JSON to get XML, or switch direction and paste XML to get JSON. The mapping is explained below, so you know exactly how attributes, arrays and empty values are written.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Pick a direction: JSON → XML or XML → JSON.
- Paste your data on the left. The result updates as you type.
- Choose an indent or Minify, and copy the result.
The mapping
| JSON |
XML |
{"a": "x"} |
<a>x</a> |
"@id": "7" inside an object |
attribute id="7" on that element |
"#text": "hi" |
text inside an element that has attributes or children |
{"t": ["a", "b"]} |
<t>a</t><t>b</t> |
null |
an empty element <a/> |
Text and attribute values are escaped: &, < and > in text, and " in attributes. When reading XML, the five standard entities, numeric references such as A and <![CDATA[…]]> sections are decoded; comments, processing instructions and the <?xml?> declaration are skipped.
Tips
- If you control the JSON, use
@ and #text keys so the XML comes out the way you want.
- Mixed content (text between child elements) is joined into one
#text value, so the position of the text is lost.
- Namespaces are not interpreted:
ns:tag is just a name with a colon.
Frequently asked questions
How are attributes written in JSON?
A key that starts with @ is an attribute. An object for "price" with "@currency": "USD" and "#text": "9.99" becomes <price currency="USD">9.99</price>. The key #text holds the element text when it also has attributes or child elements.
How are arrays converted?
Each item becomes its own element with the key as its name, so {"tag": ["a", "b"]} gives <tag>a</tag><tag>b</tag>. Going back, repeated elements with the same name become an array; a single element stays a plain value.
Why is there a root element I did not write?
XML needs exactly one root. If your JSON is an object with a single key, that key is the root. Otherwise (several keys, a top-level array or a plain value) the tool wraps it in <root>, and array items are named <item>.
Do numbers and booleans survive a round trip?
Not as types. XML only holds text, so 42 and true come back from XML as the strings "42" and "true". null is written as an empty element and read back as null.
Is my data uploaded?
No. Both directions run in your browser; nothing is sent anywhere.