DevFormatter

XML to JSON Converter

Instantly convert XML to formatted JSON — all in your browser, no server, no signup.

Our XML Formatter converts XML to JSON in one click — paste your XML, then click Convert → JSON in the toolbar.
Open XML to JSON Converter →

How XML to JSON Conversion Works

XML and JSON are both data interchange formats, but they have very different structures. XML uses elements, attributes, and text content with an explicit tree hierarchy. JSON uses objects and arrays with a flat, type-aware model.

The converter uses fast-xml-parser to parse the XML tree and maps each construct to JSON: elements become object keys, attributes become keys prefixed with @_, repeated sibling elements with the same name become arrays, and text content of mixed elements appears as the #text key.

Some XML structures — mixed content, processing instructions, XML namespaces — don't map cleanly to JSON. Always review the output before using it in production.

Example:

XML input

<user id="1">
  <name>Alice</name>
  <role>admin</role>
</user>

JSON output

{
  "user": {
    "@_id": "1",
    "name": "Alice",
    "role": "admin"
  }
}

Frequently Asked Questions

How does XML to JSON conversion work?
The converter parses the XML document into a tree using fast-xml-parser, then maps each XML construct to its JSON equivalent: elements become object keys, attributes become keys prefixed with @_, repeated sibling elements with the same name become arrays, and text content of mixed elements appears as the #text key.
What happens to XML attributes during conversion?
XML attributes are preserved in the JSON output with an @_ prefix. For example, <user id="42"> becomes {"user": {"@_id": "42"}}. This prefix distinguishes attributes from child elements in the JSON representation.
What XML structures don't convert cleanly to JSON?
Repeated sibling elements with different tag names, XML namespaces, processing instructions, CDATA sections, and mixed content (text mixed with child elements) can produce complex or surprising JSON output. Review the converted output carefully before using it in production.
Is my data sent to a server?
No. The conversion runs entirely in your browser using fast-xml-parser. Your data never leaves your machine.
How do I convert XML to JSON in Python?
Use the xmltodict library: import xmltodict, json; data = xmltodict.parse(xml_string); json_str = json.dumps(data, indent=2). Or with the standard library: use xml.etree.ElementTree to build a tree and write a recursive function to convert nodes to dicts.

Related Tools

Other free developer tools available on DevFormatter.