Turn an XML document into JSON

An API response, a config file, an old RSS feed — when the downstream code wants JSON, convert the structure instead of re-mapping fields by hand.

Tools used in this guide

The job

XML is still common in feeds, sitemaps, and enterprise APIs, but modern code usually wants JSON. The converter maps the tree mechanically: element children become keys, repeats become arrays.

How to do it

Paste the XML and convert. The result is formatted JSON you can copy or download. The mapping rules are predictable: attributes get an @ prefix, text inside mixed content lands under #text.

  • A single <item> stays an object; repeated <item> siblings become an array — check the output shape before coding against it.
  • Comments, processing instructions, and the doctype are dropped.

Worked example

<user id="42"><name>Ada</name></user> becomes {"user":{"@id":"42","name":"Ada"}} — the attribute surfaced as @id, the text as the element's value.

Limits

One mapping convention, no configuration — other tools that use $ or different prefixes produce different JSON, so do not mix outputs in one pipeline. Input up to 300,000 characters. Malformed XML reports a parse error rather than guessing.