What is JSON to XML conversion?
JSON to XML conversion transforms JSON's key-value and array structure into hierarchical XML elements. Keys become element tags, nested objects become nested elements, and arrays become repeated sibling elements. It's needed to integrate with XML-based enterprise systems, SOAP APIs, and legacy applications that still require XML for data exchange.
This converter is powered by fast-xml-parser and runs 100% in your browser with zero network requests, so your payloads never leave your machine.
Edge cases & gotchas
- Arrays map to repeated sibling elements, not a container plus items.
- Multiple top-level keys (or a non-object root) require a synthetic
<root>wrapper because XML allows only one root. - Keys starting with digits or containing spaces are not valid XML tag names and get sanitized.
null→ empty/self-closing element; empty string → empty element.- Numbers and booleans become text nodes, so type information is lost.
- Special characters are escaped, not CDATA-wrapped, by default.
JSON → XML mapping reference
| JSON | XML |
|---|---|
{ "k": "v" } | <k>v</k> |
{ "@_attr": "v" } | attr="v" (attribute) |
{ "#text": "v" } | element text value |
[a, b] | repeated <key>a</key><key>b</key> |
null | <key/> (empty) |
| number / boolean | text node |
| multiple top-level keys | wrapped in <root> |
How to use
- Paste or type JSON into the Input pane, or upload a
.jsonfile. - Set options: root element name, array item name, indentation, and whether to include the XML declaration.
- Well-formed XML renders live in the Output pane.
- Copy the result or download it as a
.xmlfile. - Malformed JSON? Repair-aware parsing fixes trailing commas and comments before converting.
Examples
Basic object → nested elements
{ "user": { "id": 1, "name": "Ada" } }<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<id>1</id>
<name>Ada</name>
</user>
</root>Array → repeated elements (edge case)
{ "colors": ["red", "green", "blue"] }<root> <colors>red</colors> <colors>green</colors> <colors>blue</colors> </root>
Attributes + special characters
{ "note": { "@_lang": "en", "#text": "Tom & Jerry <3" } }<note lang="en">Tom & Jerry <3</note>
FAQ
How do JSON arrays convert to XML?
Each array item becomes a repeated element sharing the same tag name. XML has no native array type, so there is no container, just siblings.
How do I create XML attributes from JSON?
Prefix the key with @_ (the fast-xml-parser convention), e.g. "@_id": "5" → id="5". Use #text to set the element's text value alongside attributes.
Is JSON to XML conversion lossless?
No. XML has constructs (attributes, namespaces, comments, mixed content) with no JSON equivalent, so a full round-trip is not guaranteed. Use XML to JSON for the inverse.
What is the root element and can I rename it?
XML requires a single root. A non-object root or multiple top-level keys are wrapped in a default <root> element, which you can rename.
How are null values handled?
null becomes an empty/self-closing element, e.g. <key/>. An empty string produces an empty element too.
Are special characters escaped?
Yes. &, <, > and attribute quotes are escaped to keep the XML well-formed. Content is not wrapped in CDATA by default.