How to use XML to JSON
- Paste your XML into the input box, or click Open a file to load an .xml file.
- Choose the JSON indentation and, if you want, turn on "Detect numbers and booleans".
- Read the JSON in the output box; XML errors show the line and column.
- Click Copy or Download to save data.json.
Features
- Attributes are kept, prefixed with @_
- Repeated elements become JSON arrays
- Optional detection of numbers and booleans (off by default, so values stay text)
- Validates the XML first and reports line and column
- Runs in your browser, so the XML is never uploaded
Supported formats and limits
- Maximum input: 10,000,000 characters
Examples
| Input | Result |
|---|---|
| <book id="7"><title>Dune</title><year>1965</year></book> | { "book": { "title": "Dune", "year": "1965", "@_id": "7" } } — All values stay text by default. |
| <book id="7"><title>Dune</title><year>1965</year></book> | { "book": { "title": "Dune", "year": 1965, "@_id": 7 } } — With "Detect numbers and booleans" on. |
| <a> <b></a> | Invalid XML at line 2, column 4: Expected closing tag 'b' (opened in line 2, col 1) instead of closing tag 'a'. |
Limitations
- XML and JSON do not map one to one. Comments and processing instructions are not kept, and mixed content (text between elements) may be simplified.
- An element that appears once gives a value while the same element repeated gives an array, so the shape of the JSON depends on the data.
- The converter checks that the XML is well-formed, but does not validate it against a DTD or XSD schema.
Learn more
XML is a markup language for structured documents and data. It has elements, attributes and text, and a document must be well-formed: one root element, every tag closed, tags properly nested, and attribute values in quotes.
JSON has no attributes and no mixed content, so converting XML to JSON involves conventions. A common one, used here, prefixes attribute names with @_ so they do not collide with child elements of the same name, and turns repeated sibling elements into an array. That last rule means the JSON shape can change depending on whether an element occurs once or several times, something to keep in mind if other code reads the result.
XML carries no type information, so "1965" is just text until something decides otherwise. Leaving values as text is the safest default; convert to numbers and booleans only when you know the data fits.
Frequently asked questions
How are XML attributes shown in JSON?
Each attribute becomes a key that starts with @_, for example @_id for id="7".
Why is a number shown as text?
XML has no data types, so by default every value is kept exactly as text, which avoids losing leading zeros. Turn on "Detect numbers and booleans" to convert them.
What happens to repeated elements?
Elements with the same name inside one parent are collected into a JSON array.
Is my XML uploaded?
No. The conversion runs in your browser.
Sources
- Extensible Markup Language (XML) 1.0, W3C Recommendation
- RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format
Last reviewed: September 30, 2026