✦ tomai
Free · Developer Tools

XML to JSON

Convert XML documents into clean, predictable JSON

XML input
JSON output

What is an XML to JSON converter?

XML to JSON translates legacy markup into plain objects through a compact, predictable scheme, parsed by a small recursive-descent tokenizer with no DOM dependency. Attributes land under keys prefixed with double at signs, so an id attribute never collides with a child element of the same name, element text lives under a dedicated text key, repeated siblings collapse into arrays so no repeated entry is lost, comments and processing instructions are dropped, CDATA sections merge in as ordinary text, and a leaf holding nothing but text collapses straight to that string.

Feeds, envelopes and legacy configs in JSON

  • Convert a catalog where several book elements repeat and watch them fold into a real array, with attributes like the book code preserved alongside titles and prices, ready for JavaScript or Python to consume natively.
  • Bring RSS feeds, SOAP envelopes or old config files into modern pipelines, using the bundled catalog sample to learn the shape, then copy the pretty-printed result or download it as output.json.

Malformed markup and shape surprises

  • Mismatched close tags, unclosed declarations, comments, CDATA or tags, and empty input each produce their own named error rather than half a document, and stray top-level text is skipped instead of inventing a root.
  • Attribute values always arrive as strings even when numeric, and a lone text leaf has no text wrapper, so consumers should expect a bare string there rather than an object.

The parser runs wholly in page script and the page makes no network requests at all, keeping legacy payloads private. Your markup is transformed inside the tab and never leaves your computer.

Last updated · 2026-09-01

The mapping this converter uses

  • XML attributes become keys prefixed with @ (price currency="EUR" → {"@currency":"EUR"}) so they never collide with child elements.
  • An element that mixes text and children keeps its text under #text; a plain-text element maps to a bare string.
  • Repeated sibling elements collapse into arrays; the XML declaration, comments and processing instructions are dropped.

Attributes and text nodes need a convention

⚡

Attributes and text, never mixed

Attributes become "@@id"-style keys and text lives under "@text", so an attribute and an element with the same name can never overwrite each other.

🔒

Lists stay lists

Repeated sibling elements collapse into a JSON array automatically — a catalog of five books becomes an array of five objects, not one overwritten book.

🎯

Tolerant of real XML

CDATA, comments, DOCTYPE and self-closing tags all parse cleanly, while genuinely malformed XML fails with a descriptive message.

Frequently asked questions

How are attributes represented?⌄

Attributes become keys prefixed with "@@", e.g. <book id="5"> becomes {"@@id":"5"}. This prevents the classic collision between an attribute named "id" and a child element also named "id".

What happens to repeated elements?⌄

Repeated sibling elements with the same name are grouped into a JSON array automatically. A single occurrence stays a single object, and multiple occurrences become an array — both cases read intuitively.

Is my XML uploaded anywhere?⌄

No. Everything runs in your browser with plain JavaScript — nothing you paste is transmitted or stored.

Where did my attribute go in the JSON output?⌄

Look for the @-prefixed key on the same object as its element. If you see only #text, the element had attributes AND content; if you expected an attribute and find nothing, it lived on a parent node — expand the tree one level up.

Related tools

Related tools