Guide
Formatting, checking and converting XML
XML still runs a great deal of software: SOAP services, RSS and Atom feeds, sitemaps, Android layouts, Maven and .NET project files, Office documents and countless configuration formats. It often arrives as one enormous line, or breaks because of a single misplaced character. This tool makes XML readable, finds the first error with its exact position, and converts between XML and JSON.
What well-formed means
Every XML document must follow a few strict rules. There is exactly one root element. Every opening tag has a matching closing tag, or is self-closed like <item/>, and tags close in the reverse order they opened. Attribute values are in quotes, and an attribute appears only once per element. The characters < and & cannot appear literally in text; they must be written as < and &. The checker applies these rules and reports the first violation with its line and column — for example, <a><b></a> gives “Expected </b> (opened on line 1) but found </a> (line 1, column 7)”.
Pretty-printing
Formatting puts each element on its own line, indented by 2 or 4 spaces or a tab. Elements that contain only text stay on one line, so <title>XML Developer’s Guide</title> remains readable instead of being split over three lines. Comments, CDATA sections, processing instructions such as the XML declaration, and DOCTYPE declarations are kept in place.
Minifying
Minify removes the whitespace between elements and drops comments, producing the smallest equivalent document for transmission or embedding. Text inside elements keeps its spaces, so content is not altered.
Converting XML to JSON
XML and JSON model data differently, so the conversion follows widely used conventions. The root element becomes the top-level key. Attributes become keys with a prefix, @ by default, so id="bk101" becomes "@id": "bk101". When an element has attributes or children as well as text, the text goes under #text. Elements that repeat, such as several book elements, become an array. Empty elements become null. With typing on, values that look like numbers or booleans become JSON numbers and booleans; turn it off to keep everything as strings, which is safer for codes with leading zeros.
Converting JSON to XML
The reverse direction understands the same conventions: prefixed keys become attributes, #text becomes element text, and arrays become repeated elements. A JSON object with one top-level key uses it as the root; otherwise the result is wrapped in a root element.
A worked example
The sample catalogue arrives on one line. Formatted, it starts with <catalog> followed by an indented <book id="bk101" format="paperback">. Converted to JSON, the first book’s price becomes {"@currency": "USD", "#text": 44.95} and the second title is decoded to “Midnight Rain & Other Stories”.
What it does not check
Well-formedness is not validity. A document can be perfectly formed and still break the rules of its own format, such as a required element missing from an invoice. Checking that needs the format’s DTD or XML Schema, which this tool does not apply.
Related tools
Format JSON with the JSON Formatter, flatten XML records into a table with XML to CSV, switch between YAML and JSON with YAML to JSON, or build and check feeds with the RSS Feed Generator.
Checked against the current version of the XML Formatter & XML ⇄ JSON on .

