JSON to XML

Turn JSON into XML, or XML back into JSON. The conversion stays in the browser.

A tree in the other syntax

JSON and XML can hold the same tree, but the punctuation is different. This page writes JSON as elements, or reads elements back into JSON. It is not a schema checker and it does not keep the numeric type on the way back. Pretty-printing JSON alone is JSON formatter. YAML is JSON to YAML.

How to use it

  1. Paste JSON or XML. Choose JSON to XML or XML to JSON.
  2. Root element is the outer tag when you write XML. The default is root. Array item name is used when the JSON value is an array at the top; the default is item.
  3. Pretty print adds line breaks and indentation. Turn it off for one line.
  4. Show example alternates. One click sends {"name":"Ada","n":2,"tags":["a","b"]} to XML. The next click sends that XML back to JSON.

How values are written

An object becomes nested elements. An array becomes the same tag repeated. A top-level array is wrapped in the root, and each entry uses the item name. A key that starts with @ becomes an attribute. #text becomes the text inside a tag. null becomes an empty tag. Names must start with a letter or underscore. Digits, spaces and most punctuation in a key are rejected. On the way back, repeated sibling tags become a JSON array, attributes come back as @name, and every value is text, so 2 returns as "2". A tag the browser cannot parse shows an XML error. Broken JSON shows a JSON error.

Where people use it

  • Handing a small JSON config to a tool that only accepts XML.
  • Reading a short XML snippet into JSON so you can format it.
  • Checking how an array of tags will look before you write a converter.

Questions

The number came back in quotes.

XML has no number type in this conversion. Text content is a JSON string. Put the number back yourself if the next step needs a number.

A key was rejected.

XML names cannot start with a digit and cannot contain a space. Rename the key, or use letters, digits, _, - and . after the first character.