What is XML to JSON conversion?
XML is verbose, schema-heavy markup common in enterprise, SOAP, and legacy feeds; JSON is the compact, JS-native format modern APIs use. Converting XML to JSON makes the data trivial to consume in web apps. The catch is attributes, mixed content, and the single-vs-array ambiguity, which this tool handles predictably by prefixing attributes with @_ and text nodes with #text.
Edge cases & gotchas
- Single-vs-multiple ambiguity: one child = object, many = array. Downstream code should normalize (always treat as array), since the shape depends on the data.
- Attributes need the
@_prefix or they'd collide with element names. - Namespaces: prefixes like
soap:clutter keys; there's no clean JSON analog. - Types: XML is all strings; numbers and booleans stay quoted unless type inference is enabled.
- Empty / self-closing tags (
<active/>) become an empty string or empty object. - Non-object root / bare value: wrapped in
<root>so the output is valid JSON.
XML → JSON mapping rules
| XML construct | JSON result |
|---|---|
| Element | key |
| Attribute | @_name key |
| Repeated siblings | array |
| Text content | #text |
| CDATA | plain-text string |
| Self-closing tag | empty string |
| Non-object root | wrapped in <root> |
How to use
- Paste XML into the Input pane, or upload a
.xmlfile. - Convert: fast-xml-parser maps elements to keys and attributes to
@_keys. - Repeated siblings become a JSON array; a non-object root is wrapped in
<root>. - Choose indentation or minify.
- Copy the result or download it as
.json.
Examples
Basic nesting
<book><title>JSON Basics</title><author>A. Smith</author></book>
{
"book": {
"title": "JSON Basics",
"author": "A. Smith"
}
}Attributes + repeated elements → array
<library> <book id="b1" lang="en"><title>JSON Basics</title></book> <book id="b2" lang="fr"><title>XML Guide</title></book> </library>
{
"library": {
"book": [
{ "@_id": "b1", "@_lang": "en", "title": "JSON Basics" },
{ "@_id": "b2", "@_lang": "fr", "title": "XML Guide" }
]
}
}Mixed content (attribute + text)
<price currency="USD">42.00</price>
{ "price": { "@_currency": "USD", "#text": "42.00" } }FAQ
Why convert XML to JSON?
JSON is lighter, easier to parse in JavaScript, and API-friendly compared to verbose XML.
How are XML attributes handled?
Prefixed with @_ (e.g. @_id) to distinguish them from child elements.
How are repeated elements handled?
Two or more similar siblings become a JSON array; a single occurrence stays an object.
What about CDATA?
Extracted as plain text; the wrapping markup is stripped.
Can I convert complex / SOAP / WSDL XML?
Yes, though namespaces (soap:Envelope) carry into keys and may need cleanup.
Is my data uploaded?
No. fast-xml-parser runs in your browser; verify zero requests in DevTools. Going the other way? Try CSV to JSON or YAML to JSON.