Free Online XML Formatter & Validator
Format, validate, and convert XML to JSON.
XML is checked with the browser's DOMParser. In the JSON view, attributes are stored
in an attributes object and text is stored under #text. Repeated sibling tags become arrays.
About the XML Formatter and Validator
XML is a markup language for exchanging structured data. It appears in sitemaps, RSS feeds, SOAP APIs, configuration files, office documents, and many enterprise systems. Because XML is strict, a single missing closing tag, an unquoted attribute, or an unescaped ampersand can make an entire document invalid. This tool formats XML for readability and checks well-formedness before you send the data to another system.
The formatter parses your input with the browser's built-in DOMParser, then walks the resulting
tree and rebuilds it with consistent indentation. Elements, attributes, text nodes, comments, CDATA sections,
processing instructions, and the XML declaration are preserved. Whitespace-only text between elements is
removed so the output is clean, while text inside elements is kept. If the document cannot be parsed, the
tool shows a clear error message, including the line and column when the browser provides them.
XML to JSON conversion
- Elements become object keys named after the tag.
- Repeated tags become arrays, so multiple
itemelements stay in order. - Text-only elements become strings for a compact result.
- Attributes are stored in a nested attributes object so they do not collide with child element names.
- Mixed content stores the combined text under
#textalongside the child elements.
There is no single official XML-to-JSON mapping, so different libraries make different choices. This tool follows a predictable convention that works well for feeds, catalogs, configuration files, and API payloads. If your application expects a different shape, use the formatted XML as a starting point and adapt the conversion in your own code.
How to use the formatter
- Paste XML into the editor on the left.
- Choose two spaces, four spaces, or tab indentation.
- Review the formatted XML and the JSON tab.
- Copy the result or download it as an XML or JSON file.
Frequently asked questions
What does "well-formed" mean?
Well-formed XML follows the basic syntax rules: every tag is closed, tags are nested correctly, attribute values are quoted, and special characters are escaped. It does not check whether the document matches a DTD or XML Schema.
Why does my XML with an unescaped ampersand fail?
In XML, the ampersand starts an entity reference. Write & for a literal ampersand. The same applies to a bare less-than sign inside text.
Is my XML uploaded anywhere?
No. Parsing, formatting, validation, and JSON conversion all happen locally in your browser. The document never leaves your device.