Data Formats

XML Formatter & Converter

Format XML and convert it to and from JSON, with namespace and attribute handling.

  • History kept on this deviceRecent results are kept in this browser's local storage until you clear them.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
Readable JSON is one-way, so it cannot be converted back. Choose Ordered to convert to XML.

XML

JSON

Parsed document

Parsed document tree appears here.

What each control does

  • Readable and Ordered choose the shape of the JSON. Pressing one changes the mode only and does not run anything.
  • Convert to JSON reads the XML pane and writes only the JSON pane.
  • Convert to XML reads the JSON pane and writes only the XML pane. It is available in Ordered mode only, because Readable JSON is one-way.
  • Copy copies the text of the last result. It is off until a run has produced text, and off again after you edit a pane or change the mode.
  • Cancel stops a run in the background. It appears only while one is running.

The two JSON shapes

  • Readable: the parser runs with preserveOrder off, so each element is a key, attributes come first as @_ names, repeated elements become a list, and comments are dropped. Every value stays text. It is one-way, so it cannot be converted back.
  • Ordered: the parser runs with preserveOrder on, so the JSON is a list of nodes in document order: { "name": [children], ":@": { "@_attribute": "value" } } for an element, { "#text": "โ€ฆ" } for text, and #comment and #cdata nodes that each hold one #text. It converts back.

Limits

  • Readable JSON is one-way. Sibling order across different tag names, mixed content and comments are not recoverable. Text and attribute values are trimmed, one child is a value while several are an array, CDATA sits under #cdata, and ?xml appears as a key. A name with no value in an XML declaration, and a repeated pair, are lost with no notice.
  • Ordered mode round-trips, with these exceptions: a DOCTYPE is dropped; a processing instruction keeps only its name="value" pairs, the last of a repeated name; whitespace outside the root is dropped; <a/> is written <a></a>; attribute quotes and spacing inside a tag are normalized, with a " or ' inside a value written &quot; or &apos;; and CRLF and a lone CR become LF in text, attribute values, comments and CDATA. Ordered JSON holds XML's own text, so &amp; stays &amp;, and JSON written by hand must do the same.
  • What is not checked. No DTD or XSD validation. Namespace URIs are not resolved or checked. "Well-formed" means what the pinned library checks, and it allows these: a < or a bare & in an attribute value, ]]> in text, an undefined entity reference, a reference that is not one, such as &1a;, &#; or &#x;, a:b:c as a name, control characters, lone surrogates, and <?xml โ€ฆ?> after the first tag.
  • Well-formed documents this page refuses (a false refusal, because the check it relies on is stricter or differs): a < or > that does not balance in a quoted literal or a comment in a DOCTYPE; a processing instruction in an internal subset; a name with a four-byte character, U+1680 or U+FEFF; an instruction pair whose name is not an XML name; an instruction with a quote open at its first ?>, such as an apostrophe in its free text; and a reference in text whose name holds anything but ASCII letters, digits and _, or runs past 20 characters.
  • Refused as not well-formed: a declaration after the root starts, a comment holding -- or ending in -, a closing tag ending in />, and an instruction whose target is not an XML name. These are accepted by the library and misread by its parser or builder, so they are refused by name.
  • Entity expansion is disabled for untrusted XML. Declared entities are read and never expanded, and references to them stay as text. The five predefined entities and numeric references decode in Readable mode only. A parameter entity, an external entity, or more than 64 declarations is refused.
  • Nothing is fetched. SYSTEM identifiers, an external DTD and xi:include are never resolved. This is structural here, and the page's content security policy stands behind it.
  • Reserved names. Elements named __proto__, constructor or prototype are refused, because the library cannot keep them. Attributes of those names are data.
  • Formatting. Whitespace is added to an element whose text sits beside another node, ends in >, or holds /> or </, and the page counts those. Where text sits beside a child, more whitespace is added on each format. The formatter does not honor xml:space, writes <a/> as <a></a>, and keeps a DOCTYPE directly before the root.

Bounds

  • Input bytes: 8.0 MB for an XML source, and 16.0 MB for the JSON of Convert to XML. Larger input is refused before it is read.
  • Depth: 64 levels for Format XML, Validate XML and Readable JSON, counting the outermost as 1, and 31 levels for Ordered JSON, because Ordered JSON nests two levels of JSON for each level of XML, and a comment, CDATA section or processing instruction counts as a level. Deeper input is refused.
  • Keys: 200000, counting elements, attributes, comments, CDATA sections, processing instructions and text runs that are not only whitespace, the same way for XML and for Ordered JSON. More is refused.
  • Entity declarations: 64, and no external entity. More is refused, before the document is read.
  • Output: 16.0 MB of JSON, and 8.0 MB of XML. XML output stops at the XML input bound so the page can read every document it writes, which means that a large document can convert to JSON and not come back. A result that would be larger is refused, and nothing is cut. An estimate of the XML to be written can refuse a document whose text would have fitted.
  • Time: 30 seconds for a background run. A run that takes longer is stopped.
  • Listed warnings: at most 1000 repeated keys are listed, and the rest are counted.
  • Rendered path: at most 500 characters of a path in a message, cut with an ellipsis.
  • Tree: at most 1000 children under a node, with a final node that counts the rest, and values cut at 200 characters with an ellipsis. The JSON pane, not the tree, is the complete output.
  • Readable JSON can nest deeper than the JSON limit, because a repeated sibling at each level doubles the depth, and it has no way back.

Runs

  • Documents of 64.0 KB or more run in the background and can be cancelled. Smaller ones run at once and cannot be cancelled.
  • A failed run leaves its target pane as it was.
  • State larger than 128.0 KB is not saved. The run still completes, and the page says so.
  • A very large document can run out of time, a large document can stop the tab on a device with little memory, and a very large result can pause the page briefly.

Example

Press Convert to JSON in Readable mode on <a id="1"><b>x</b></a> to get:

{
  "a": {
    "@_id": "1",
    "b": "x"
  }
}

In Ordered mode the same document gives:

[
  {
    "a": [
      {
        "b": [
          {
            "#text": "x"
          }
        ]
      }
    ],
    ":@": {
      "@_id": "1"
    }
  }
]

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.