XML to JSON Converter

Paste XML or open a file, choose how attributes and text should look in JSON, and press Convert to JSON. Malformed XML is reported with its line and column.

Try an example
Conversion style
The file is read in your browser and placed in the box.

About this XML to JSON converter

XML and JSON both describe nested data, but XML has things JSON lacks, such as attributes, mixed text and tags, and repeated elements, so there is more than one way to convert it. The standard style, based on the BadgerFish convention, marks attributes with @ and stores text that sits beside child elements under #text. Compact style puts attributes in as ordinary keys, which reads better but can clash with child names. JsonML keeps document order exactly as nested arrays, and Preserve gives every element the same predictable shape. Repeated child elements always become arrays. The XML is checked strictly first, and every error is reported with its line and column.

How to convert XML to JSON

  1. Add your XML. Paste XML, open a file such as an RSS feed or SVG, or press an example.
  2. Pick a style and options. Choose standard, compact, JsonML, or preserve, set the indentation, and decide whether to detect numbers, sort keys, and keep namespace prefixes.
  3. Press Convert to JSON. Copy or download the JSON, and expand the tree preview to explore it. Errors show the line with a caret under the problem.

Frequently asked questions

Which conversion style should I choose?

Use standard when you need to convert back to XML or keep attributes clearly marked. Use compact for the simplest JSON to read in code. Use JsonML or Preserve when the order of mixed elements matters.

How are repeated elements handled?

When an element contains the same child more than once, such as several <book> or <author> tags, those children become a JSON array. A single child stays a plain value.

What does detect numbers and booleans do?

Text such as 9.99, 250, true, or false becomes a JSON number or boolean instead of a string. Turn it off to keep every value as text, for example to preserve leading zeros in codes.

What happens to namespaces?

With Keep namespace prefixes on, names stay as written, such as soap:Body, and xmlns attributes are kept. Turn it off to drop the prefixes and the xmlns declarations for cleaner keys.

Are comments and processing instructions converted?

No. Comments, the XML declaration, processing instructions, and the DOCTYPE are not data, so they are left out of the JSON. CDATA sections are treated as text.