Three jobs in one tool
XML work splits into formatting and converting, and this tool covers both directions of each:
| Task | What it does | When |
|---|---|---|
| Beautify | Indents and line-breaks messy XML | Reading / debugging |
| Minify | Strips whitespace for transport | Production payloads |
| XML → JSON | Converts to a JS-friendly object | Consuming XML in JS |
| JSON → XML | Converts back to markup | Producing XML output |
How attributes survive the conversion
XML’s attribute/element distinction has no JSON equivalent, so the converter uses a convention: attributes become keys prefixed with @, and an element’s text content (when it also has attributes) lands under a #text key. So <book id="bk1">Title</book> becomes { "book": { "@id": "bk1", "#text": "Title" } }. This preserves every piece of information for a lossless round-trip — and tells you exactly what to look for when navigating the resulting JSON.
CDATA: escaping without the escaping
When an element’s text is full of characters that would otherwise need escaping — an HTML snippet, a code sample, a string with many <, >, and & — wrapping it in a CDATA section (<![CDATA[ ... ]]>) tells the parser to treat the contents as literal text, not markup. It’s far more readable than escaping every character into entities. The formatter preserves CDATA sections; reach for them whenever you’re embedding markup-like content inside XML.
Fixing “not well-formed” errors
The DOMParser reports a specific error when XML breaks the rules, and the cause is almost always one of a short list: an unclosed tag, an unescaped & (use & — common in URLs), more than one root element, or a tag name starting with a digit. Escape the five reserved characters (&, <, >, ", '), ensure a single root, and most parse failures resolve. All parsing happens locally via the browser’s native APIs, so your XML never leaves your device.