XML to JSON Converter

Convert XML to JSON format instantly. Handles attributes, nested elements, and repeated tags automatically.

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

When to Use XML to JSON

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

Edge cases & gotchas

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.