Quick answer
An XML-to-JSON converter parses the XML tree and maps it to JSON: the root becomes the top key, attributes go under @attributes, repeated tags become arrays, and element text becomes string values. This tool runs on the browser's native XML parser, outputs 2-space JSON, and keeps namespace prefixes in the keys — entirely in your browser, so nothing is uploaded. Paste XML, click Convert to JSON, then copy or download.
How This Tool Converts XML to JSON
- The root XML element becomes the top-level key in the JSON output. Child elements become nested JSON object properties, preserving the original structure.
- XML attributes are placed in an
@attributesobject inside the element's JSON representation — for example,<user id="1">becomes{ "user": { "@attributes": { "id": "1" } } }. - Repeated sibling elements sharing the same tag name are automatically collapsed into a JSON array — three
<role>elements become"role": ["admin", "editor", "viewer"]. - Text-only elements become string values. When an element contains both text and child elements, the text is placed under a
#textkey alongside the child element keys.
When to Use XML to JSON
- When consuming a SOAP or legacy REST API that returns XML and you need to process the response with a JSON-native tool or language.
- When migrating data from an XML-based system (RSS feeds, sitemap files, legacy exports) into a JSON API or database.
- When you receive an XML configuration file and want to inspect or query it with JSONPath or
jq. - When integrating with third-party services that return XML and your application only handles JSON payloads.
Worked example
XML with an attribute, leaf elements, and a repeated tag — the cases that determine the JSON shape:
Input XML
<?xml version="1.0" encoding="UTF-8"?>
<user id="42">
<name>Jane Smith</name>
<age>28</age>
<roles>
<role>admin</role>
<role>editor</role>
</roles>
</user>
Output JSON
{
"user": {
"@attributes": {
"id": "42"
},
"name": "Jane Smith",
"age": "28",
"roles": {
"role": [
"admin",
"editor"
]
}
}
}
What happened
- The root
<user>became the top-level key, and itsidattribute landed in a separate@attributesobject. - The two
<role>elements collapsed into a JSON array underrole— had there been only one, it would have been a plain string instead (see gotchas). ageis"28"— a string, not the number 28. XML values carry no type, so everything comes out as a string.- The
<roles>wrapper is preserved as an intermediate object, so the array sits atroles.role, not directly underuser.
Edge cases & gotchas
- Every value is a string.
<age>28</age>becomes"28"and<active>true</active>becomes"true". Cast to real numbers or booleans in your code after converting. - Single vs repeated changes the shape. One
<role>produces a string; two or more produce an array. Consumers that always expect an array break on a one-item list — normalise it after converting. - Attributes live under
@attributes. The output shape isn't the same as a JSON document authored by hand, because XML's attribute/element split has no JSON equivalent and is preserved with a special key. - Namespace prefixes stay in the keys.
<soapenv:Envelope>becomes a key literally namedsoapenv:Envelope— convenient for SOAP, but remember the colon is part of the key. - Mixed content uses
#text. An element with both text and child elements keeps its text under a#textkey alongside the children; whitespace-only text is dropped.
Frequently Asked Questions
How are XML attributes handled in the JSON output?
XML attributes are placed in an @attributes object inside the element's JSON representation. For example, <user id="1"> becomes { "user": { "@attributes": { "id": "1" } } }.
How are repeated XML elements converted?
Repeated sibling elements with the same tag name are automatically converted to a JSON array. Three <role> elements become "role": ["admin", "editor", "viewer"].
Is my XML data sent to a server?
No. All conversion happens entirely in your browser. Your data never leaves your device.
What happens when an XML element has both text and child elements?
When an element contains both text content and child elements, the text is placed under a #text key alongside the other child keys. For example, <item>Note: <name>Alice</name></item> becomes { "item": { "#text": "Note: ", "name": "Alice" } }.
Can this tool convert SOAP XML?
Yes. SOAP envelopes convert to nested JSON objects. Namespace prefixes such as soapenv: or ns: are preserved as part of the key names in the output — <soapenv:Envelope> becomes a key named soapenv:Envelope in the JSON.
Are numbers and booleans preserved as types?
No. XML has no type system, so every value comes out as a JSON string. An element like <age>28</age> becomes "age": "28", not the number 28, and <active>true</active> becomes the string "true". Cast the values in your application after converting if you need real numbers or booleans.
Why does a list with one item convert differently from a list with several?
Repeated sibling elements become a JSON array, but a single element becomes a plain value. So one <role> produces a string while two or more <role> elements produce an array. This is the classic XML-to-JSON ambiguity: the JSON shape depends on how many items happened to be present. If your code expects an array, normalise it after converting (for example, wrap a lone value in an array) so a one-item list doesn't break it.