Skip to content

XML Formatter

Make XML readable, shrink it, or convert it to JSON.

  • Free, no account
  • Nothing uploaded
  • 13 tools
Input
Output
working…in 257 B · 1 linesProcessed in this tab, no request made

Nothing you paste is uploaded. The server sends connect-src 'self', so your browser blocks this page from contacting any other host. Check it yourself

Indent or minify XML and convert it to JSON. The document is checked for well-formedness first and the first error is shown by line and column.

Formatting, minifying and checking XML

The document is first checked for well-formedness: every tag closed and properly nested, attribute values quoted, one root element. If that fails you get the line and column. If it passes, Format puts each element on its own line with the indentation you choose, and Minify removes the whitespace between tags.

Text content, attribute values, comments, CDATA sections and the XML declaration are written exactly as they came in. Only whitespace between tags changes.

XML to JSON

XML has attributes and mixed content, which JSON lacks, so a convention is needed:

<item sku="BOLT" qty="200">zinc</item>

{ "item": { "#text": "zinc", "@_sku": "BOLT", "@_qty": "200" } }

Attributes get the prefix @_, text next to attributes or child elements goes under #text, and repeated sibling elements become an array. Values stay strings. This check is about well-formedness only: it does not validate against an XSD or DTD.

Send the JSON on to the JSON formatter to browse it as a tree.

Questions

Short answers to what people ask most.

Does formatting change the content of my XML?

Only whitespace between tags changes. Text inside an element, attribute values, comments and CDATA sections are kept as written. If whitespace between tags is significant in your format (mixed content, xml:space="preserve"), do not reformat it.

What does the validation check?

Well-formedness: matching and properly nested tags, quoted attributes, a single root. It does not validate against a DTD or an XSD schema.

How are attributes represented in the JSON output?

As keys prefixed with @_, next to the child elements, and text that sits beside child elements is stored under #text. All values stay strings so that leading zeros and long numbers are not altered.

Can I format HTML with it?

Only if the HTML is also well-formed XML (XHTML). Regular HTML with unclosed tags such as <br> or <img> will be reported as an error.