XML to JSON Converter

Paste XML and instantly convert it to a structured JSON object.

🔒 100% private — runs entirely in your browser

or try sample data

What is XML to JSON?

XML to JSON converts XML documents into equivalent JSON objects. The converter uses the browser's built-in DOMParser for reliable XML parsing, then recursively walks the DOM tree to produce structured JSON output.

XML attributes are mapped to keys prefixed with @ (e.g., @id, @class). Text content in mixed elements uses the #text key. When multiple child elements share the same tag name, they are automatically grouped into a JSON array.

This is useful for consuming XML APIs, converting legacy XML configs to JSON, or migrating SOAP service responses to a more modern format. All processing happens in your browser — no data leaves your machine.

XML to JSON — Conversion Examples

Attributes and nested elements

<user id="42" role="admin"> <name>Alice</name> <email>alice@example.com</email>
</user> // Converts to:
{ "user": { "@id": 42, "@role": "admin", "name": "Alice", "email": "alice@example.com" }
}

Repeated children become arrays

<items> <item>Apple</item> <item>Banana</item> <item>Cherry</item>
</items> // Converts to:
{ "items": { "item": ["Apple", "Banana", "Cherry"] }
}

Repeated elements with the same tag are automatically grouped into arrays.

XML to JSON Gotchas

Single vs. multiple children

A single <item> child produces a plain value, while two or more produce an array. If your code always expects an array, you may need to normalize the output. This is a fundamental XML-to-JSON mapping challenge.

Mixed content

XML elements with both text and child elements use #text for the text portion. This can result in unexpected JSON structures if the XML has heavily mixed content.

Namespaces

XML namespace prefixes (e.g., xs:element) are preserved in tag names. The converter does not strip or resolve namespace URIs.

Frequently Asked Questions

How are XML attributes converted?

Attributes are prefixed with @ in the JSON output. For example, <book id="1"> produces {"@id": 1}. This convention keeps attributes separate from child elements.

How are repeated elements handled?

When multiple child elements share the same tag name, they are grouped into a JSON array. A single child with a unique tag becomes a plain value.

What about CDATA sections?

CDATA content is treated as text and included in the #text field or as the element's value if there are no child elements.

Can I convert invalid XML?

No. The XML must be well-formed. If the parser detects errors (unclosed tags, invalid characters), you'll see an error message with details about the issue.

Is my data safe?

Yes. The XML is parsed using your browser's built-in DOMParser. Nothing is sent to any server.