XML to JSON Converter

Parse XML with the browser's own parser and get a clean JSON object that keeps attributes and repeated elements.

Loading tool…

About the XML to JSON

The XML is parsed with the browser's built-in DOMParser, so malformed input is rejected with the line and column of the problem instead of producing half a result. The root element becomes the single top-level key.

Conversion rules: attributes become keys prefixed with @ (<price currency="USD"> → "@currency": "USD"); an element that appears more than once under the same parent becomes an array; an element with only text becomes a string; when an element has both attributes or children and text, the text goes into #text. CDATA sections are read as text, and comments and processing instructions are dropped.

Note that a list with a single child is not an array, because XML alone cannot say it should be; check for that in your code. Detect numbers & booleans converts values such as 44.95 and true; turn it off to keep every value a string. Namespace prefixes stay in key names, e.g. soap:Body.

How to use it

  1. Paste XML or open an .xml file.
  2. Choose whether to detect numbers and booleans.
  3. Pick the JSON indentation.
  4. Copy the JSON or download it.

Frequently asked questions

Why is a single element not an array?
Repeated elements become arrays, but one element is indistinguishable from a plain child. Normalise with Array.isArray(x) ? x : [x] in your code.
How are XML namespaces handled?
Prefixes are kept as part of the key ("soap:Envelope") and xmlns declarations appear as @xmlns attributes.
Why does it say Invalid XML?
The document is not well-formed: an unclosed tag, an unescaped & or <, or more than one root element. The message gives the line.

Related tools