Converters

XML to JSON Converter


Paste XML and get clean, pretty-printed JSON in your browser, with attributes, mixed text, and repeated elements mapped sensibly and a chosen indent.

An XML to JSON Converter transforms structured XML markup into a JSON object you can use in modern APIs and JavaScript.

Paste your XML, pick an indent, and get pretty-printed JSON that preserves attributes, text, and nested elements.

How the conversion maps XML to JSON

The converter parses your XML with DOMParser and walks the tree element by element.

Attributes are grouped under an @attributes key, and text that sits alongside child elements is kept as #text.

When a tag repeats, like several <item> siblings, those become a JSON array so nothing is lost.

Formatting and error handling

You choose the indent β€” two spaces, four spaces, a tab, or minified β€” and the JSON reformats live with a short debounce.

If the XML is malformed, the tool detects the parser error and shows a clear message instead of broken output.

When the result looks right, copy it to your clipboard or download it as a .json file.

Where this fits in a JSON workflow

Converting between markup formats is a routine part of working with data.

Once you have JSON, a JSON Formatter helps you tidy, validate, and re-indent it before you commit it.

To go the other way, a JSON to XML Converter rebuilds markup from an object, and when you just need cleaner source a XML Formatter pretty-prints the original XML.

Frequently Asked Questions

How are XML attributes represented in the JSON?

Attributes on an element are collected into an @attributes object on that node. So an element like item id="5" becomes a JSON object containing @attributes with an id of 5. This keeps attributes distinct from child elements and text.

How are repeated XML elements handled?

When the same tag appears more than once under a parent, those elements are grouped into a JSON array in document order. A single occurrence stays a plain object, so the structure matches what the XML actually contains.

What happens if my XML is invalid?

The converter uses the browser's XML parser and checks for a parser error. If your XML has unbalanced or malformed tags, it clears the output and shows a message asking you to check the markup, rather than producing partial or misleading JSON.

Is my XML sent to a server?

No. All parsing and conversion happens locally in your browser with JavaScript. Nothing you paste is uploaded, logged, or stored, and the tool keeps working offline once the page has loaded.