Free tool
XML formatter & converter
This free XML formatter pretty-prints messy XML with your choice of indentation, minifies it back down to one line, and converts XML to JSON or JSON to XML — live, as you type, with clear error messages when the input isn't well-formed. Parsing happens with your browser's built-in engine, so nothing is ever uploaded to a server.
XML formatter & converter
Pretty-print or minify XML and convert XML ⇄ JSON — live, with clear error messages, entirely in your browser.
Action
Indent
0 B
Result appears here…0 B
Parsing uses your browser's built-in DOMParser, and formatting is a recursive walk over the resulting DOM — no libraries, no server. Your XML and JSON never leave this tab, so the tool works offline and is safe for configs, feeds, and API payloads. In XML → JSON output, attributes become @name keys, element text becomes #text, and repeated sibling elements become arrays.
How to format XML online
- Paste your XML. Drop it into the left pane, click Load file to open an .xml, .svg, or feed file from disk, or hit Sample to see the tool working on example data immediately.
- Pick an action. Choose Format to pretty-print, Minify to strip whitespace, XML → JSON to convert to JSON, or JSON → XML for the reverse direction. For Format and the converters you can also choose the indent: 2 spaces, 4 spaces, or tabs.
- Read the result. The output pane updates automatically about a third of a second after you stop typing. If the input isn't valid, a plain-English error appears instead, including the line number reported by the parser.
- Copy or download. Use the Copy button next to the output, or download the result as an .xml or .json file, depending on the action.
There's no convert button and no page reload — every keystroke, action switch, and indent change re-runs the conversion live.
What Format and Minify actually do
Format parses your document into a DOM tree and re-serializes it with one element per line, children indented one level deeper — the classic XML beautifier output that makes structure obvious. Attributes stay on their element, empty elements collapse to the self-closing form, comments and CDATA sections are preserved, and elements that contain text (or a mix of text and inline elements) stay on a single line so the formatter never invents whitespace inside your actual content. If the document starts with an XML declaration, it's kept at the top.
Minify is the same walk in reverse: it drops the whitespace that only exists for human eyes — indentation and line breaks between elements — while leaving text content intact. Minified XML is smaller to store and transmit, which matters for payloads sent on every request. The savings are shown in the status bar as bytes in versus bytes out, so you can see exactly what the whitespace was costing. One honest caveat: in XML, whitespace inside mixed content can be meaningful, so the minifier collapses runs of whitespace in text to a single space rather than deleting them outright.
XML to JSON converter — the mapping rules
XML and JSON model data differently — XML has attributes, text, and repeated elements; JSON has objects, arrays, and values — so any XML to JSON converter has to pick a convention. This tool uses the widely adopted one, and applies it predictably:
| In the XML | In the JSON |
|---|---|
An attribute, e.g. id="bk101" | A key prefixed with @: "@id": "bk101" |
| Element text next to attributes or child elements | A "#text" key holding the text |
Repeated sibling elements, e.g. several <book> elements | One "book" key holding an array |
| An element with only text inside (no attributes) | A plain string value |
| The root element | The single top-level key of the JSON object |
Values are kept as strings rather than guessed into numbers or booleans — "13.99" stays a string — because silently converting "007" to 7 or a postal code to a number is exactly the kind of surprise a converter shouldn't spring on you. Once converted, the JSON formatter can validate, re-indent, or minify the result further.
JSON to XML — the reverse direction
JSON to XML applies the same convention backwards: keys starting with @ become attributes, a #text key becomes the element's text content, arrays become repeated sibling elements, and ordinary keys become child elements. The JSON is validated first — if it doesn't parse, you get the JavaScript engine's error message translated into a line and column instead of a silent failure. If the JSON has a single top-level key, that key becomes the XML root element; otherwise the output is wrapped in a <root> element, since XML requires exactly one root.
Two details worth knowing. JSON keys that aren't legal XML names (spaces, leading digits, symbols) are sanitized — invalid characters become underscores — because <first name> simply isn't parseable XML. And round-tripping is faithful for data that fits the convention: convert the sample XML to JSON and back, and you get equivalent markup. Data that only exists in one model — comments, processing instructions, attribute order — is where any converter, this one included, has to make choices.
Reading XML error messages
When parsing fails, the tool surfaces the browser parser's own diagnosis, including the line and column it points at. The usual suspects, in rough order of frequency:
- Unescaped ampersands. A bare & in text or a URL must be written as
&— this is the single most common reason a feed or config “suddenly” stops parsing. - Mismatched or unclosed tags. Every element needs a closing tag (or a self-closing slash), and closing tags must match opening tags exactly — XML is case-sensitive, so an opening
<Item>closed by</item>is an error. - Multiple root elements. A document must have exactly one top-level element; two siblings at the top level make it invalid (a common result of concatenating files).
- Unquoted attribute values —
id=5must beid="5"— and stray characters before the XML declaration, like a BOM or leading whitespace from a copy-paste.
Because validation re-runs on every keystroke, the moment you fix the reported line the error box flips to the green “Valid XML” status with an element count — a fast loop for cleaning up a broken file.
XML vs JSON: when each format wins
JSON has won the API-payload war, but XML remains everywhere real systems live: RSS and Atom feeds, XML sitemaps, SVG images, Maven and NuGet configs, Android layouts, SOAP services, invoice standards like UBL, and decades of enterprise integrations. XML's strengths — attributes, namespaces, comments, schema validation, mixed text-and-markup content — matter in documents; JSON's strengths — direct mapping to objects and arrays, less syntax, native browser support — matter in APIs. Which is exactly why converting between them is such a routine chore: a JavaScript service needs to consume a legacy SOAP response, or a sitemap needs to become JSON for a build script. This json to xml and XML-to-JSON pair exists for that boundary. If your pipeline speaks YAML instead, the YAML to JSON converter covers that hop.
An XML viewer for feeds, sitemaps, and configs
Format mode doubles as an XML viewer online: paste a minified RSS feed, a sitemap downloaded from a CMS, an SVG file, or an API response, and the indented output makes the structure readable enough to actually navigate. The status bar confirms the document is well-formed and reports how many elements it contains — a quick sanity check before you feed a sitemap to a search console or debug why a feed reader rejects your RSS. Because the output pane scrolls horizontally rather than wrapping, deeply nested documents keep their indentation intact instead of turning into visual soup.
Is this XML formatter safe and private?
Yes. Parsing uses DOMParser, the XML engine built into your browser, and the formatter, minifier, and converters are small JavaScript routines running in this tab. Your XML and JSON are never attached to a network request, never logged, and never stored — which matters, because config files and API payloads routinely contain endpoints, credentials, and customer data that have no business passing through a random formatting server. It also means the tool works offline and has no size cap beyond your device's memory.
Who uses an XML formatter?
- Backend developers debugging SOAP responses, Spring configs, and legacy integrations.
- SEO specialists inspecting XML sitemaps and RSS feeds before submitting them.
- Android developers tidying layout and manifest files outside the IDE.
- Data engineers converting XML exports to JSON for pipelines that only speak JSON.
- Ops & support teams reading vendor XML payloads to answer “what did their system actually send us?”
Working with other developer formats too? The SQL formatter and JSON to TypeScript generator live in the same toolbox.
Frequently asked questions
- Is this XML formatter free?
- Yes — free and unlimited, with no account and no file-size plan. All processing runs in your browser, so there's no server cost to meter.
- Is my XML uploaded to a server?
- No. Parsing uses the DOMParser engine built into your browser, and formatting is local JavaScript. Your data never leaves the tab, and the tool keeps working offline once loaded.
- How does the XML to JSON conversion handle attributes?
- Attributes become keys prefixed with @ (id becomes "@id"), element text next to attributes or children becomes a "#text" key, and repeated sibling elements collapse into a JSON array. Elements containing only text become plain strings.
- Can it convert JSON back to XML?
- Yes. The JSON is validated first, then the same convention runs in reverse: @-prefixed keys become attributes, #text becomes element text, arrays become repeated elements, and a single top-level key becomes the root element.
- Why does my XML fail to parse?
- The most common causes are unescaped & characters (write & instead), mismatched or unclosed tags (XML is case-sensitive), more than one root element, and unquoted attribute values. The error message includes the line number the parser stopped at.
- Does it validate against a schema (XSD/DTD)?
- No — it checks well-formedness (correct syntax and structure), which is what browsers' XML engines do. Schema validation against an XSD requires tooling beyond what runs client-side here.