XML to JSON
Convert XML documents to JSON format.
Last updated: August 2026
Attributes are ignored; element text and nesting are preserved.
Was this tool helpful?
Turning markup into objects
XML carries three kinds of information: element nesting, attributes on those elements, and the text between tags. JSON has no attributes, so a converter must fold them in somehow, typically into special keys. The choices a tool makes here define how usable the result is in your code.
The attribute problem
A common convention prefixes attributes with @ and stores text under a key like #text. That keeps everything but makes the shape verbose. Other tools drop attributes entirely or merge them with child elements, which is simpler to read but silently loses data. Knowing which strategy your converter uses matters before you build code against the output.
Example
XML input:
<user id="42" active="true">
<name>Ada</name>
</user>JSON with attributes preserved:
{
"user": {
"@id": "42",
"@active": "true",
"name": "Ada"
}
}Single child versus list
The trickiest edge case: one <item> becomes an object, but two <item> elements become an array. Code that assumes an array breaks the moment a document happens to contain a single item. If you control the schema, force arrays consistently; if you do not, write parsing that tolerates both shapes.
FAQ
Why is my number a string? XML text has no type, so 42 comes out as "42". You have to cast it yourself after conversion.
What about namespaces? Prefixes like ns:tag usually survive as part of the key name, colon and all, which can be awkward in JavaScript where you then need bracket access. Going the other direction is handled by JSON to XML.