LocalToolkit
HomeData Converters › XML to JSON Converter

XML to JSON Converter

A parser that refuses malformed XML instead of guessing, and says which tag broke it.

🔒 Runs in your browser. Nothing is uploaded — verify it in the network panel, or disconnect and try again.

The three questions every XML converter answers differently

  1. Where do attributes go? Here they become keys prefixed with @, so <item id="7"> becomes {"@id": "7"}.
  2. Where does element text go? When an element has attributes and text — <a id="1">x</a> — the text becomes a #text key, because it has to coexist with the attributes. When an element has only text, the text is the value: <name>Ada</name> becomes simply "Ada".
  3. How are repeated siblings handled? Two or more children with the same tag become an array; a single child stays a scalar. This is the pragmatic choice, and it is why consumers often fail when a list happens to contain exactly one item.

That last point is a genuine hazard in production systems. An API that returns <item> once for a single result and twice for a list produces JSON of two different shapes, and the client breaks on the day the list has one element. Robust code normalises by checking the type before iterating — or you convert with a schema that declares which elements are always collections.

What this parser rejects

Well-formed is not the same as valid

A parser can only check well-formedness — that tags nest, close and appear once as a root. It cannot check that the document matches a DTD or XSD schema, that required attributes are present, or that element order follows the rules. Those are separate, schema-level concerns. So a successful conversion means 'this was parseable', not 'this document is correct'.

Common sources of XML that will not convert

How to use it

  1. Paste XML or an RSS/Atom feed.
  2. Choose whether the root element should become a wrapper key in the output.
  3. Convert.
  4. If parsing fails, read the reported tag name — it identifies the exact malformation.

Worth knowing

  • Attributes become keys prefixed with @; element text with siblings becomes #text.
  • Repeated sibling tags become arrays; a single occurrence stays a scalar.
  • Only well-formedness is checked — never DTD or schema validity.
  • Real-world HTML is usually not well-formed and will fail to parse.

Limitations

  • Namespaces are kept literally in tag names and not resolved to URIs.
  • Entity references defined in a DTD are not expanded.
  • A single-element list produces a scalar, which consumers must accommodate.
  • Mixed text-and-element content is flattened into a text key alongside child keys.

Frequently asked questions

How do I convert an RSS feed to JSON?
Paste the feed XML directly. RSS and Atom are well-formed XML, so they convert cleanly, and repeated <item> or <entry> elements become an array.
Why does an HTML snippet fail to parse?
Because HTML is not XML. Browsers tolerate unclosed <br>, <img> and <li> tags; an XML parser does not. Use an HTML parser for HTML, or convert the fragment to XHTML first.
How are attributes represented?
As keys prefixed with @<a id="1"/> becomes {"@id": "1"}. When the element also has text, the text is stored under a #text key so both can coexist.
Why is a list sometimes an array and sometimes not?
Because a single repeated tag is indistinguishable from a non-repeated one, so it stays a scalar. Declare which elements are always collections in your schema and normalise on read.
Related tools
JSON to XML ConverterHTML Entity Encoder / DecoderJSON Formatter & ValidatorCSV to JSON ConverterJSON MinifierJSON to CSV Converter
Keep reading
How browser-only processing worksAll Data Converters toolsEvery tool on the site