xml to json converter

typetools

instant, client-side type converter • 0ms network latency

root:
inputxml
paste or drop file
291 chars
outputjson
*.json
{
  "@id": "usr_98a7c2f1",
  "@active": true,
  "username": "alex_dev",
  "email": "[email protected]",
  "score": 98.4,
  "role": [
    "admin",
    "editor"
  ],
  "metadata": {
    "lastLogin": "2026-10-15T12:00:00Z",
    "ipAddress": "192.168.1.1"
  }
}
0.15ms•in-browser
documentation, edge cases & specifications below

step-by-step integration guide

technical specification differences & end-to-end conversion workflow

Reconciling XML's Document-Centric DOM with JSON's Key-Value Data Model

Extensible Markup Language (XML) and JSON were designed with fundamentally different structural primitives. An XML element can simultaneously contain named attributes (<item id="42" status="active">), child elements, mixed text nodes, XML namespaces (xmlns:soap), and <![CDATA[...]]> sections. Furthermore, XML does not have an explicit array syntax: a list of items is simply represented by repeating child elements with the same tag name under a parent node. When an XML parent contains only a single child element (<items><item>A</item></items>), a naive converter emits a single JSON object instead of an array, breaking client code that expects a list.

DOM Tree Traversal, Attribute Prefixing, and Array Coalescing

Our XML-to-JSON engine parses raw XML markup into a strict Document Object Model (DOM) AST inside your browser without external network calls. As the serializer walks the DOM tree, XML attributes on each element are preserved using a clean prefix convention (@_attributeName) so they never collide with child element tags of the same name. Mixed text content inside an element with attributes is assigned to a dedicated #text key, and <![CDATA[...]]> blocks are unwrapped directly into properly escaped JSON strings. Whenever the parser encounters multiple sibling elements sharing the same tag name, it automatically coalesces them into a unified JSON array while optionally inferring primitive numeric and boolean types for leaf text nodes.

frequently asked questions

common developer questions answered

q:How are XML attributes (like <user id="10" role="admin">) preserved in the JSON output?

Attributes are mapped as keys prefixed with '@_' (such as '@_id' and '@_role') inside the corresponding JSON object, ensuring they never overwrite a child element with the same name.

q:How does the converter handle repeated XML child elements with the same tag name?

When multiple sibling elements share the same tag name under a parent node, the AST walker automatically groups them into a single JSON array under that tag key.

q:Are XML CDATA sections and HTML entities decoded properly?

Yes. Raw text inside <![CDATA[...]]> blocks and standard XML entities (&amp;, &lt;, &gt;, &quot;) are cleanly decoded and serialized as valid UTF-8 JSON strings.

topic cluster

related type & ast converters

3 interconnected tools