🔄 XML to JSON Converter

📄
Characters: {{ xmlInput.length }}
🏷️
📝
🔧
⚡
{{ result.isValid ?'✅' :'❌' }}
{{ result.isValid ?'XML successfully converted to JSON' :'XML contains errors' }}
🚨
{{ error }}
⚠️
{{ warning }}
📤
{{ result.json }}
Characters: {{ result.stats.jsonSize }}
📊
Elements:
{{ result.stats.elements }}
Attributes:
{{ result.stats.attributes }}
Text Nodes:
{{ result.stats.textNodes }}
Max Depth:
{{ result.stats.depth }}
Root Element:
<{{ result.stats.rootElement }}>
Namespaces:
{{ Object.keys(result.stats.namespaces).length }} namespace(s) found
💾
Original XML: {{ result.stats.originalSize }} chars (~{{ Math.round(result.stats.originalSize / 1024 * 100) / 100 }} KB)
JSON Output: {{ result.stats.jsonSize }} chars (~{{ Math.round(result.stats.jsonSize / 1024 * 100) / 100 }} KB)
{{ result.stats.jsonSize > result.stats.originalSize ?'Increase:' :'Decrease:' }} {{ Math.abs(result.stats.originalSize - result.stats.jsonSize) }} chars
💾
⚠️ {{ error }}

ℹ️ About XML to JSON Converter

XML to JSON conversion turns an element-and-attribute XML document into a JSON object that is easier to inspect, pass to JavaScript, or feed into REST API tooling. XML is built around a single document element with nested elements, attributes, namespaces, text, and CDATA; JSON represents structured data with objects, arrays, strings, numbers, booleans, and null.

Use this online XML to JSON converter when you need to migrate an XML API sample into JSON, inspect a SOAP or RSS-style payload, convert configuration snippets for test fixtures, or compare how attributes and repeated child elements will map before writing parser code. For example, <book id="bk101"><price>44.95</price><available>true</available></book> can become JSON like {"book":{"@id":"bk101","price":44.95,"available":true}} when attributes, numeric conversion, and boolean conversion are enabled.

How this converter maps XML to JSON:

  • Element names become object keys, and the document root remains the top-level JSON key.
  • Repeated sibling elements with the same name become JSON arrays so multiple values are preserved.
  • Attributes can be preserved with a prefix such as @id, _id, or a custom empty prefix.
  • Text inside mixed-content elements is stored under the selected text-node key, such as _text.
  • CDATA text is treated as text content, while comments and XML processing instructions are ignored.
  • Namespace prefixes can be preserved or stripped, depending on whether you need compact output or exact names.

Useful conversion options:

  • Preserve XML attributes: keep IDs, language tags, href values, and metadata that would otherwise be lost.
  • Ignore namespaces: convert atom:title to title for simpler JSON, while noting that name collisions can occur.
  • Convert numbers and booleans: turn 123 into a JSON number and true into a JSON boolean when that is safe for your data.
  • Remove empty elements: omit blank tags from the result when you need compact fixtures or API examples.
  • Pretty print JSON: format the result with indentation for debugging, documentation, and code review.

Standards and source references: XML well-formedness and markup syntax are defined by the W3C XML specification, namespace names by Namespaces in XML, and the XML data model by the XML Information Set. JSON syntax is standardized by RFC 8259 and ECMA-404.

Limitations and security notes:

  • This is structural conversion, not XML Schema, DTD, XSD, or JSON Schema validation.
  • Type coercion can change semantics: IDs such as 00123 may need to remain strings.
  • Ignoring namespaces can merge distinct names, such as a:id and b:id.
  • Mixed-content XML cannot always be represented in JSON without choosing a convention for text-node keys.
  • Very large or deeply nested XML can hit browser memory limits; test representative payloads before automating a workflow.
  • When parsing untrusted XML in server-side code, follow OWASP XXE prevention guidance and keep external entity resolution disabled.

API Usage Example:

POST /api/tools/webdev/xml-to-json
Content-Type: application/json

{
    "xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><users><user id=\"1\"><name>John Doe</name><email>[email protected]</email><active>true</active></user><user id=\"2\"><name>Jane Smith</name><email>[email protected]</email><active>false</active></user></users>",
    "prettyPrint": true,
    "preserveAttributes": true,
    "attributePrefix": "@",
    "textNodeName": "_text",
    "removeEmptyNodes": false,
    "numericConversion": true,
    "booleanConversion": true,
    "ignoreNamespaces": false
}
Ready