XML Formatter and Validator: Pretty Print XML and Convert XML to JSON

Pretty print XML with tidy indentation, minify it onto a single line, or validate that it’s well-formed, with the line and column of the first error. Convert XML to JSON and back again. Works with sitemaps, RSS feeds, SVG, SOAP messages, Android layouts and config files, entirely in your browser.

  • Beautify and minify
  • Error line and column
  • XML to JSON and back

How to use the XML Formatter tool

  1. Add your XMLPaste it or open a file such as .xml, .svg, .rss or .kml.
  2. Pick an actionFormat, Minify, XML → JSON or JSON → XML; output refreshes as you type.
  3. Check validityA green notice confirms well-formed XML, while a red one points to the first problem.
  4. Copy or saveCopy the output, download it as a file, or feed it back in as the next input.

XML formatter features

  • XML pretty printerIndent with 2 spaces, 4 spaces or tabs, keeping short text values on a single line for readability.
  • Nothing lostAttributes, comments, CDATA blocks, processing instructions, the XML declaration and DOCTYPE all survive.
  • XML validatorRuns your browser’s strict XML parser and reports the line and column of the first error.
  • XML ↔ JSON conversionAttributes become “@name”, text becomes “#text” when needed, and repeated elements turn into arrays.
  • PrivateData stays on your device, so it’s safe for API responses and internal configuration.

Common XML errors and how to fix them

  • Unclosed tag: <city>Delhi needs its end tag, <city>Delhi</city>, or an empty element can close itself, as in <hr/>.
  • Overlapping tags: <p><em>text</p></em> must close in reverse order, </em></p>.
  • Raw ampersand: <firm>Smith & Sons</firm> must use &amp;, or put the text inside CDATA.
  • Unquoted attribute: <row n=3> has to become n="3".
  • More than one root: <x/><y/> needs a single element wrapping everything.
  • Content before the declaration: even a space or byte-order mark ahead of <?xml is an error, because the declaration must come first.
  • Mismatched case: <Order>…</order> fails because XML is case-sensitive, so spell both tags identically.

Well-formed vs valid XML

This validator confirms that XML is well-formed: every tag is closed and properly nested, every attribute is quoted, and there’s exactly one root element. A document can be well-formed yet still not valid for a particular system, which compares it against a schema (XSD or DTD) listing permitted elements. If a sitemap or e-invoice is rejected despite being well-formed, check it against that format’s specification.

How XML is converted to JSON

<movie year="1999"><name>The Matrix</name><genre>sci-fi</genre><genre>action</genre></movie>

{ "movie": { "@year": "1999", "name": "The Matrix", "genre": ["sci-fi", "action"] } }

Attributes receive an @ prefix, an element containing only text becomes a string, and repeated elements become an array. JSON → XML reverses the process. Values stay as text, because XML has no native numbers or booleans.

Formatting vs minifying XML

Formatted XML is easy to read, review and compare in the Text Diff Checker. Minified XML strips the indentation between tags, making it smaller for APIs and storage. Formatting trims whitespace inside text values, so keep the original if spacing within an element matters, as with poetry or code. For JSON, use the JSON Formatter, and to create a sitemap, try the XML Sitemap Generator.

Frequently asked questions

How do I format XML online?
Paste the XML with “Format” selected, choose 2 spaces, 4 spaces or tabs, then copy or download the result.
How can I find the error in my XML?
When the XML isn’t well-formed, a red message shows the line and column of the first error and explains the problem.
Can I convert XML to JSON?
Yes. Pick “XML → JSON”; attributes become keys beginning with @ and repeated tags become arrays.
Can I convert JSON to XML?
Yes. Pick “JSON → XML” and paste JSON; keys beginning with @ become attributes.
Does it work with SVG, RSS feeds and sitemaps?
Yes. Any XML-based format can be formatted, minified and validated.
Does my XML get uploaded?
No. Everything is processed in your browser.