Indent:
XML Input 0 B
Ready
0 chars
JSON Output 0 B
JSON output will appear here...
0 chars
Features

Why use this converter

Native parser

Uses the browser's built-in DOMParser for maximum compatibility and speed. Handles namespaces, CDATA, processing instructions, and comments.

Attribute mapping

XML attributes become JSON keys prefixed with @. Text content of leaf elements is rendered as primitive values with type inference.

Array detection

Repeated child elements with the same name are automatically collected into a JSON array. Single elements stay as scalar values — no awkward single-item arrays.

How it works

Conversion explained

1. Parse XML

The browser's DOMParser builds a DOM tree from your input. Parse errors are detected and reported clearly.

2. Walk DOM

The converter walks the DOM recursively. Element nodes become object properties, attribute nodes become @-prefixed keys, text nodes become values.

3. Infer types

Text content is checked against number, boolean, and null patterns. Matching values are converted; everything else stays as a string.

FAQ

XML to JSON Converter — frequently asked questions

How are XML attributes represented in JSON?

Attributes become keys prefixed with @. For example, <user id="123"/> becomes {"user":{"@id":"123"}}.

What happens to mixed content?

Mixed content (elements with both text and child elements) is rare in data-oriented XML. JSONLab puts text content under a #text key alongside any child elements.

Are namespaces supported?

Yes, namespaces are preserved as part of element and attribute names. No namespace resolution is performed — names are kept verbatim.

Why is XML-to-JSON conversion lossy?

XML carries information that JSON cannot represent directly: comments, processing instructions, CDATA sections, attribute order, and mixed content. JSONLab preserves the data but loses some metadata.