How to convert XML to JSON
- Paste your XML into Input (XML), open an
.xmlfile, or click Sample. Any XML syntax errors are underlined as you type. - Choose your Indent style (2 spaces, 4 spaces, tab, or minified) and configure Prefix attributes with @, Parse numbers & booleans, or Unwrap root element.
- Click Convert to JSON, then copy the JSON output or download it as a
.jsonfile.
How XML elements, attributes and text map to JSON
Elements become JSON properties, and sibling elements that share the same tag name are grouped into a JSON array automatically.
- Attributes and mixed text: attributes are included on the element's object (prefixed with
@by default, matching the JSON to XML Converter). When an element has both attributes and text content, the text is placed under"#text". - Numbers & booleans: with Parse numbers & booleans checked, numeric text and
true/falsebecome native JSON numbers and booleans while leading-zero strings (like"007"or postal codes) stay strings and integers above 253 keep every digit. - Empty elements: self-closing tags without attributes (such as
<note/>) becomenullin JSON. - CDATA & entities:
<![CDATA[...]]>sections and XML character references (such as&or😀) are decoded into plain UTF-8 JSON strings.
Example: XML to JSON conversion
Input XML:
<catalog version="1.0">
<book id="b1">
<title>The Pragmatic Programmer</title>
<price currency="USD">42.5</price>
<inStock>true</inStock>
</book>
</catalog>Converted JSON output:
{
"catalog": {
"@version": 1.0,
"book": {
"@id": "b1",
"title": "The Pragmatic Programmer",
"price": {
"@currency": "USD",
"#text": 42.5
},
"inStock": true
}
}
}Frequently asked questions
- How does the converter decide between a JSON object and a JSON array?
- When a parent element has multiple child elements with the same tag name (such as several
<book>elements inside<catalog>), they are automatically grouped into a JSON array. A single child element with a unique tag name becomes a single property. - Why are strings with leading zeros (like "007" or ZIP codes) kept as strings?
- Even when Parse numbers & booleans is enabled, values with leading zeros are preserved as JSON strings so codes like postal codes, phone numbers, and padded identifiers do not lose their leading zeros. Standard numbers and integers above 253 are emitted as exact JSON numbers.
- What does the Unwrap root element option do?
- By default, the root XML element becomes the top-level key of the JSON object (for example
{"catalog": {...}}). Checking Unwrap root element omits that outer wrapper and outputs the root element's contents directly.