Convert XML to JSON
Paste XML below and get JSON. The parser uses the browser's own XML engine, so invalid XML gives a precise error. Attributes become `@`-prefixed keys, repeated tags become arrays, and numeric or boolean text is coerced automatically.
It uses the browser's native DOMParser — the same XML engine the browser trusts — so parsing matches the spec and your XML never leaves the page.
How to convert XML to JSON
- Paste your XML. Drop a well-formed XML document into the box. If it is invalid, you get the parser's exact error message instead of silent bad output.
- Click Convert to JSON. Elements become keys, attributes become @-prefixed keys, and elements that repeat under the same parent become a JSON array.
- Copy the JSON. Copy the pretty-printed JSON. Numeric and boolean text is coerced so <age>36</age> becomes a number, not a string.
Elements, attributes and text
Each XML element becomes a JSON key. Attributes are preserved as keys prefixed with @, so <user id="7"> yields "@id": "7". When an element has both attributes and text, the text is stored under #text.
Repeated elements become arrays
If the same tag appears more than once under one parent, those values collapse into a JSON array — two <roles> elements become "roles": ["admin","dev"]. A tag that appears once stays a single value, so shape depends on the input.
Type coercion
Leaf text that looks like a number, true, false or null is converted to the matching JSON type. Everything else stays a string. Empty elements become null.
FAQ
How are repeated tags handled?
Elements that repeat under the same parent become a JSON array. Because of this, an element that appears once is a scalar and the same element appearing twice is an array — the output shape follows the input.
What happens to XML attributes?
Attributes are kept as keys prefixed with @, for example @id. If an element has attributes plus text content, the text goes under a #text key.
Is the number 007 kept as a string?
A value like 007 is kept as a string because it does not match a plain numeric pattern once you consider leading zeros; only clean integers and decimals are coerced to numbers.
Does invalid XML fail loudly?
Yes. Parsing uses the browser's DOMParser, and any parse error is surfaced as a clear message rather than producing partial JSON.