XML to JSON

Convert well-formed XML to JSON with a documented convention: attributes as @name, text as #text, text-only elements as strings, repeated siblings as arrays.

Developer Tools Runs in your browser · no upload

Reviewed 17 November 2026 · Free · No account needed

ExecutionYour browserInput never leaves your tab
File retentionNoneNothing is stored
AccountNot requiredNo sign-up, no paywall
PriceFreeNo trial, no usage cap on the tool itself

How to use

  1. Paste XML or choose an .xml file.
  2. Press Convert — the markup is tokenised, validated and mapped to JSON.
  3. Copy the JSON or download it as a .json file.

Example

Input: <person id="7"><name>Ada</name><tags><t>x</t><t>y</t></tags></person>

Output: {"person":{"@id":"7","name":"Ada","tags":{"t":["x","y"]}}}

How it works

The XML document is parsed into a tree and each element becomes a JSON object: attributes and child elements become keys, and text content becomes the value.

The document is validated, then mapped with a fixed convention: attributes become "@name" keys, text content becomes "#text", an element holding only text (and no attributes) becomes a plain string, and repeated sibling elements become an array. The root element's name is kept as the top-level JSON key.

Worked example

<person id="7"><name>Ada</name><tags><t>x</t><t>y</t></tags></person> gives {"person":{"@id":"7","name":"Ada","tags":{"t":["x","y"]}}}.

Edge cases to know

  • Input must have exactly one root element — several roots are refused with their names listed.
  • Processing instructions, doctypes and comments are skipped.
  • A lone child element becomes a plain value, not a one-element array; repeated siblings keep document order.
  • Mixed content collects all text under #text.

Limits & compatibility

  • Mixed content collects text under #text; element order within a name grouping is preserved.
  • Processing instructions, doctypes and comments are skipped.
  • Input must have exactly one root element.

Privacy

Conversion runs locally in your browser. Nothing is uploaded.

Related tools

FAQ

Questions about XML to JSON

What convention does the conversion follow?

A documented, deterministic one: attributes become "@name" keys, text content becomes "#text", an element with only text and no attributes becomes a plain string, and repeated sibling elements become arrays while a single occurrence stays a single value. The root element's name is preserved as the top-level JSON key so round-tripping stays unambiguous.

What happens to mixed content, CDATA and comments?

Text scattered among child elements is collected under #text, and CDATA sections are treated as text. Processing instructions, doctypes and comments are skipped entirely rather than appearing in the output. The JSON is pretty-printed with a 2-space indent and can be copied or downloaded as a .json file.

Why is my multi-root document rejected?

Because the output shape depends on it: JSON has one top-level value, and the converter preserves the root element's name as that key, so input must contain exactly one root element. When several are found the error names them all. Conversion runs locally in the browser with no upload.