Converters
XML to JSON Converter
Parse any XML document into clean JSON — repeated elements become arrays, attributes preserved, text nodes kept.
In short
XML to JSON maps each element to a JSON key: an element that repeats becomes an array, one that appears once becomes an object or scalar, attributes are kept under an @ prefix, and text beside attributes lands under #text. Numeric-looking values become numbers. The document is validated first, so malformed XML reports the exact line and column.
By NaveenKumar T · Updated
- Instant in-browser conversion
- Validates input first
- Attributes preserved with @ prefix
Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →
Example
XML to JSON: input and output
A small library catalogue: two <book> elements with id and available attributes, a <price> that has both an attribute and text, and an empty <notes/> element.
<catalog>
<book id="101" available="true">
<title>The Left Hand of Darkness</title>
<author>Ursula K. Le Guin</author>
<price currency="EUR">12.50</price>
<pages>304</pages>
</book>
<book id="102" available="false">
<title>Kindred</title>
<author>Octavia E. Butler</author>
<price currency="USD">9.99</price>
<notes/>
</book>
</catalog>{
"catalog": {
"book": [
{
"title": "The Left Hand of Darkness",
"author": "Ursula K. Le Guin",
"price": {
"#text": 12.5,
"@currency": "EUR"
},
"pages": 304,
"@id": 101,
"@available": true
},
{
"title": "Kindred",
"author": "Octavia E. Butler",
"price": {
"#text": 9.99,
"@currency": "USD"
},
"notes": "",
"@id": 102,
"@available": false
}
]
}
}The two <book> elements collapsed into a book array. Each price gained a #text key (12.50 typed as the number 12.5) beside its @currency, the id and available attributes appear after the child elements typed as a number and a boolean, and the empty <notes/> element became an empty string.
Learn more
How XML to JSON conversion works
Each XML element becomes a JSON key. When the same element repeats (a list of <item> tags), the values collapse into a JSON array; when it appears once, it's a plain object or scalar. Attributes are kept with an @ prefix (@id, @href) so they can't collide with child element names, and mixed text content lands under #text. Numeric-looking values are parsed into real numbers.
The document is validated before conversion — malformed XML reports the exact line and column of the problem instead of producing a half-converted result.
When to convert XML to JSON
Legacy and enterprise systems emit XML; modern code wants JSON. Convert SOAP responses, RSS/Atom feeds, sitemaps, Maven/NuGet metadata, or decades-old export files into JSON you can work with in JavaScript, store in document databases, or inspect with this site's JSON tree viewer — one click away after converting. Inspect the result in the JSON tree viewer or reindent it in the JSON formatter.
Help
Frequently asked questions
Everything you need to know about the XML to JSON.
01How do I convert XML with namespace prefixes such as soap: or xsi:?
Prefixes are kept as part of the key: <soap:Body> becomes a "soap:Body" key and xmlns:soap becomes "@xmlns:soap" beside it, so nothing is silently merged or dropped. Access such keys with bracket notation in JavaScript (doc["soap:Body"]). If you need prefix-free keys, strip the namespace declarations in the XML formatter first or rename them downstream.
02Where did my XML attributes go in the JSON?
They're preserved as keys prefixed with @ — <item id="7"> becomes {"item":{"@id":7,…}}. The prefix keeps attributes distinguishable from child elements of the same name, and the convention survives the reverse conversion.
03Why do some values come back as numbers or booleans, and what is the #text key?
The parser types scalar text and attribute values that look numeric or boolean: <pages>412</pages> becomes 412, available="true" becomes true, and a value with leading zeros such as id="007" becomes 7. Anything that doesn't parse cleanly stays a string, and surrounding whitespace is trimmed. When an element carries both attributes and text — <price currency="EUR">12.50</price> — the text lands under a #text key beside @currency, and attributes are listed after any child elements. An <?xml …?> declaration, if present, shows up as a ?xml key.
04Does converting the JSON back with JSON to XML reproduce my original document?
Not byte-for-byte. The new root is always named <root> (or whatever you rename it to) rather than your source document's actual root element, since that name is never recorded in the JSON in the first place, and every value comes back as plain text — an attribute this converter typed as a number is written back as ordinary XML text, which is what XML always was. Element order does follow your JSON's key order, which follows the original document.
Keep working
Related tools
JSON to XML
Converters
JSON Formatter
Format, beautify, and validate JSON instantly in a professional VS Code-style editor — free, fast, and 100% private.
JSON Viewer
Explore any JSON document in an interactive, collapsible tree — keys, types, and counts at a glance, with code view one click away.
XML to CSV
Converters
XML to YAML
Converters
RSS to JSON
Converters
Learn the format
Related guides
JSON vs XML: An Honest Comparison
JSON vs XML compared without tribalism: syntax, size, attributes, namespaces, schemas, tooling — and the cases where each format genuinely wins.
2 min readGuide · Data FormatsXML Namespaces Explained: Prefixes, Default Namespaces and Common Errors
What xmlns and xmlns:prefix do, how default namespaces scope and inherit, why attributes are excluded, and why XPath returns nothing on namespaced XML.
7 min readTutorial · Data FormatsXML Tutorial: Structure, Syntax & Survival Skills
A working developer's XML tutorial: elements, attributes, namespaces, escaping, and well-formedness rules — with the errors that actually break parsers.
2 min read