What it does
- Beautify, turns minified or messy XML into clean, indented, readable XML with 2-space indentation.
- Validate, if the XML is not well-formed, you get the exact parser error so you can find the problem fast.
- Minify, strips the whitespace between tags to make the XML as compact as possible.
- To JSON, converts the parsed XML document into a JSON object, using the convention described below.
How to use it
Paste your XML into the input box and click Beautify to pretty-print it, Minify to compress it onto a single line, or To JSON to convert it. The result appears in the output box below, ready to Copy. If anything is wrong with your markup, a missing closing tag, a stray &, or mismatched elements, a clear error message tells you what the parser found. Your XML declaration (the <?xml .. ?> line) is preserved when you beautify.
XML to JSON, the exact conversion rules
The converter uses one consistent, documented convention so the output is predictable:
- Every element becomes a JSON object key named after its tag.
- Element attributes are collected into a nested
"@attributes"object, keyed by attribute name. - An element with no attributes and no child elements collapses to a plain string, its text content, or an empty string if it has none, instead of being wrapped in an object.
- An element that has attributes and/or child elements but also carries direct text keeps that text under a
"#text"key. - Repeated sibling elements that share a tag name become a JSON array, in document order.
- Comments are dropped, since JSON has no comment concept. CDATA sections contribute their text just like ordinary text.
For example, <note id="1"><to>Tove</to><to>Jani</to></note> becomes:
{
"note": {
"@attributes": { "id": "1" },
"to": ["Tove", "Jani"]
}
}Why an in-browser XML formatter?
XML is everywhere, RSS and Atom feeds, SVG, SOAP and other API payloads, Android and .NET config files, sitemaps and build files. This tool uses your browser's native DOMParser to parse and re-serialize the document locally. There is nothing to sign up for, no file size cap, and no waiting on a network round-trip.
Frequently asked questions
Will it tell me what is wrong?
Yes, XML that is not well-formed shows the browser parser's error message so you can fix it, in every mode, including To JSON.
Does it handle comments and CDATA?
When you beautify, comments and CDATA sections are preserved. When you convert to JSON, CDATA text is included like ordinary text, but comments are dropped, since JSON has no comment concept.
What does the "@attributes" key mean in the JSON output?
It is where the converter puts an element's XML attributes. For example, <item id="1"> becomes {"@attributes":{"id":"1"}} in the "item" key. See the conversion rules above for the full convention.
Does it validate the XML?
Yes. If the XML is not well-formed, the parser error is shown so you can fix it. If it is valid, it is beautified, minified, or converted to JSON.
What does Minify do?
Minify removes the whitespace between tags to make the XML as small as possible, which is handy for transport or storage.
How does the XML to JSON conversion work?
Elements become object keys, attributes are collected under an "@attributes" key, repeated sibling elements become arrays, and text content becomes a "#text" key, or a plain string when the element has no attributes or child elements.
Related: JSON Formatter · HTML Entity Encode / Decode