1. Home
  2. Developer tools
  3. XML Formatter & XML ⇄ JSON

XML Formatter & XML ⇄ JSON

Make a one-line SOAP response, sitemap or config file readable, find the tag that breaks it, or turn it into JSON for JavaScript.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use XML Formatter & XML ⇄ JSON

  1. Paste or open XML (or JSON).
  2. Choose Format, Minify, XML → JSON or JSON → XML.
  3. Copy or download the result.

Features

  • Well-formedness check with line and column of the first error
  • Indent with 2 or 4 spaces or tabs; text-only elements stay on one line
  • Minify by removing indentation and comments
  • XML → JSON: attributes with a prefix, repeated elements as arrays, typed numbers
  • JSON → XML with attributes and text content

Supported formats

You can open

  • XML
  • JSON

You get

  • XML
  • JSON

Private by design

Your files are opened and processed by your browser on this device. They are never uploaded to openWorkstand or anyone else, so the XML Formatter & XML ⇄ JSON is safe for contracts, IDs, photos and work documents. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Checks well-formedness only; validation against a DTD or XML Schema is not performed.

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 &lt; and &amp;. 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.

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 .

Troubleshooting

The file does not open

Check that it is one of the supported formats above and opens in another app. Damaged files and password-protected PDFs cannot be read until they are repaired or unlocked.

It is slow or stops on a very large file

Everything runs on your device, so speed depends on its memory. Close other tabs, use a computer rather than a phone, or split the file into smaller parts first.

The download did not start

Look for your browser’s download bar or icon. Some browsers ask once before a site may download files; allow it and click the button again.

Frequently asked questions

Why is my HTML reported as invalid XML?

HTML allows things XML does not: unclosed tags such as <br>, attributes without values such as disabled, and bare ampersands. XHTML and HTML written to XML rules pass; ordinary HTML usually does not, and that is expected.

Does formatting change the meaning of my XML?

It only changes whitespace between elements. Text inside elements is trimmed of surrounding spaces when they are pretty-printed, which matters only for formats where leading or trailing spaces are significant, such as some XML-based documents with xml:space="preserve".

How are namespaces handled?

Prefixed names such as soap:Envelope and xmlns attributes are kept exactly as written, both when formatting and when converting to JSON, where they appear as ordinary keys. Namespace URIs are not resolved.

Is “well-formed” the same as valid?

No. Well-formed means the syntax is correct: one root, matching tags, quoted attributes. Valid means it also matches a DTD or XML Schema for that document type, which needs the schema file.

Why does my XML fail with “a bare & must be written as &amp;”?

In XML an ampersand starts an entity, so a literal & in text or an attribute must be written &amp;. URLs with query strings in XML are the most common cause.

Keep working with the result

After you download, choose “Save to Workstand” to keep the result in a folder on your computer, attach it to a project and create a follow-up task. It is saved by your browser, not uploaded.