JSON to XML Converter
Convert JSON to XML and XML to JSON in your browser. Keeps element names as written, and stops with the exact path when an array, attribute or mixed content cannot be converted.
- Runs in your browser
- Your data never leaves your browser
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Worked Examples
Simple object
Input JSON:
{"name": "Alice", "age": 30, "active": true}
Output XML (root element: root):
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>Alice</name>
<age>30</age>
<active>true</active>
</root>
Nested objects
{"server": {"host": "localhost", "port": 8080}}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<server>
<host>localhost</host>
<port>8080</port>
</server>
</root>
Arrays, null and empty objects
An array repeats the element of its key. A top-level array uses item. null and {} both become an empty element:
{"order":{"id":1001,"items":[{"sku":"A-1","qty":2},{"sku":"B-7","qty":1}],"note":null,"meta":{}}}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<order>
<id>1001</id>
<items>
<sku>A-1</sku>
<qty>2</qty>
</items>
<items>
<sku>B-7</sku>
<qty>1</qty>
</items>
<note></note>
<meta></meta>
</order>
</root>
Element names are kept as written
XML 1.0 allows letters from most scripts in names, so keys such as 名前 or straße become elements with the same
name. Text is escaped (< and &):
{"名前": "Ann", "straße": "Hauptstr. 1", "a-b.c": "x<y & z"}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<名前>Ann</名前>
<straße>Hauptstr. 1</straße>
<a-b.c>x<y & z</a-b.c>
</root>
A single value is written as the root text, with no extra spaces or line breaks inside the root element:
"hello"
<?xml version="1.0" encoding="UTF-8"?>
<root>hello</root>
When JSON → XML stops
The tool does not rename keys or drop data to make the XML fit. It writes nothing and shows the path of the first value it cannot map:
{"2026": "q", "first name": "Ann"}givesCannot convert to XML: $["2026"]: this name cannot be used as an XML element name.XML names cannot start with a digit or contain spaces. Names with:are refused as well, because a prefix needs a namespace declaration that this mapping cannot write.{"m": [[1, 2], [3]]}givesCannot convert to XML: $["m"][0]: empty or nested arrays cannot be represented by repeated XML elements.Repeated elements cannot show where one inner array ends and the next begins.{"tags": []}givesCannot convert to XML: $["tags"]: empty or nested arrays cannot be represented by repeated XML elements.An empty array would leave no element at all.
Strings with characters that XML 1.0 forbids, such as U+0000, stop the conversion the same way.
XML to JSON
Pasting this XML into the right panel:
<catalog>
<book>
<id>bk101</id>
<author>Gambardella, Matthew</author>
<price>44.95</price>
</book>
<book>
<id>bk102</id>
<author>Ralls, Kim</author>
<price>5.95</price>
</book>
</catalog>
gives (pretty print on):
{
"catalog": {
"book": [
{
"id": "bk101",
"author": "Gambardella, Matthew",
"price": "44.95"
},
{
"id": "bk102",
"author": "Ralls, Kim",
"price": "5.95"
}
]
}
}
The two book elements form an array, and 44.95 is a string.
When XML → JSON stops
<catalog><book id="bk101">…</book></catalog>givesCannot convert to JSON: /catalog/book[1]/@id: XML attributes cannot be represented by this JSON mapping.Move the value into a child element, as in the example above.<p>Hello <b>world</b>!</p>givesCannot convert to JSON: /p: mixed text and child elements cannot be represented by this JSON mapping.Text next to child elements has no place in a JSON object.
The path counts elements with the same name from 1, so book[2] is the second book under its parent.
Limits
- XML → JSON values are always strings. XML has no number or boolean type, so
<qty>2</qty>becomes“2”. Empty elements such as<b/>become"", which means JSONnulland{}come back as""after a round trip. - One child or many changes the shape.
<order><item>A</item></order>gives{"item": "A"}, but twoitemelements give an array. Code that reads the JSON must handle both. - Text in leaf elements is kept exactly, including spaces and line breaks around it. Only whitespace between child elements is ignored. Comments and processing instructions are skipped.
- Attributes, namespace declarations and mixed content stop the conversion (see above). This tool does not offer an attribute mapping such as
@idkeys. - XML syntax errors come from the browser’s parser, so the wording differs between Chrome, Firefox and Safari. To indent or minify XML without converting it, use the XML formatter.
JSON vs XML
JSON (JavaScript Object Notation) is the standard data format for REST APIs and web services — compact, human-readable, and natively supported in every language. XML (eXtensible Markup Language) remains widely used in enterprise systems, SOAP APIs, configuration files (Maven, Spring), and document formats (SVG, XHTML, RSS). This tool helps you bridge the two formats when integrating systems that speak different data languages.
FAQ
How does JSON to XML conversion work?
Each object key becomes a child element with exactly that name, values become text, an array becomes repeated elements with the same name, and null or an empty object becomes an empty element. If a key is not a valid XML name, or an array is empty or nested, the tool writes no XML and shows the path of the first problem, for example $["m"][0].
How does XML to JSON conversion work?
The browser's DOMParser reads the XML. A leaf element becomes a string, child elements become object keys, and sibling elements with the same name become an array. The root element name is the top-level key. Whitespace between child elements is ignored, comments are skipped, and CDATA counts as text.
What is the root element option?
XML needs one root element around everything. JSON → XML uses this name (default: root). It must be a valid XML name; a name such as "123 data" stops the conversion. XML → JSON ignores the option and uses the real root element name.
Are XML attributes supported?
No, and they are not dropped quietly. XML → JSON stops at the first attribute and names it, for example /catalog/book[1]/@id. Namespace declarations (xmlns, xmlns:x) are attributes too. Rewrite attributes as child elements before converting. JSON → XML never writes attributes.
Is my data sent to any server?
No. All conversion runs in your browser. Your data never leaves your machine.