How to convert XML to JSON
- Paste your XML into the left panel, upload an
.xmlfile, or load it from a URL. - The JSON appears on the right as you type. Leave Keep attributes ticked to carry attributes over as
"@_name"keys, or untick it to drop them. - Untick Detect numbers/booleans if values such as product codes or zip codes must stay strings.
- Switch the output to Tree to explore a large document, then click Copy or Download .json.
If the XML is not well-formed, the error bar explains the problem with a line and column, for example a closing tag that does not match the one that was opened.
What the output looks like
Input:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101" lang="en">
<title>JSON at Scale</title>
<price>29.99</price>
<tags><tag>data</tag><tag>api</tag></tags>
</book>
<book id="bk102">
<title>Structured Logging</title>
<price>18.50</price>
</book>
</catalog>
Output:
{
"catalog": {
"book": [
{
"title": "JSON at Scale",
"price": 29.99,
"tags": { "tag": ["data", "api"] },
"@_id": "bk101",
"@_lang": "en"
},
{
"title": "Structured Logging",
"price": 18.5,
"@_id": "bk102"
}
]
}
}
The root element becomes the single top-level key. The two book siblings become an array, price turns into a number, and attributes sit beside child elements with the @_ prefix so they cannot collide with a child named id.
The single-child gotcha
Repeated sibling tags become an array, but a tag that appears once becomes an object. If the catalog above held one book, book would be an object rather than a one-element array, and code such as catalog.book.map(...) would break on that document. XML has no way to say "a list of one", so the converter cannot know. Wrap the value with [].concat(data.catalog.book) in your code, or have the producer emit a fixed wrapper element. JSON array vs object covers the distinction in more depth.
Limits and notes
- Files up to 5 MB. Parsing runs as JavaScript in your browser; nothing is uploaded.
- Comments, processing instructions, and the XML declaration are dropped. Namespace prefixes stay as part of the key, for example
"soap:Body". - Mixed content (text beside child elements) is collected under a
#textkey; whitespace between elements is trimmed. - Empty elements such as
<note/>become empty strings, notnull. - Type detection follows numeric rules, so
18.50becomes18.5and02134becomes2134. Turn it off when the exact text matters. - Repeated tags are how XML expresses what JSON would reject as duplicate keys; the array is the faithful translation. For the wider trade-offs, see JSON vs XML, and use JSON to XML for the reverse direction.