Skip to content

JSON to XML converter

Paste JSON. Indented XML is written beside it.

Ctrl+Enter or ⌘+Enter runs this tool immediately.

Indent
JSON
XML

Waiting for input.

Parsing stays in this browser. Input is not uploaded or saved.

How to use this tool

  1. Paste JSON, or load the sample. Use an object with a single key to name the root element.
  2. Read the XML. An array under a key becomes that element repeated once per item.
  3. Copy or download the file.

Supported formats and limitations

  • XML needs one root element. If the top level has several keys or is an array, the output is wrapped in <root>, and array items become <item>.
  • Keys starting with @ become attributes, and #text becomes the element's text. This matches the XML to JSON converter, so a round trip keeps attributes.
  • Keys must be valid XML names. A key with a space or one starting with a digit is reported instead of converted.
  • null and empty objects become empty elements, such as <note/>.
  • Characters such as < and & are escaped in text and attribute values.

Examples

Attributes

{"book": {"@id": "bk101", "title": "XML"}} becomes <book id="bk101"><title>XML</title></book>.

{"book": {"@id": "bk101", "title": "XML"}}

Several top-level keys

The keys become children of a <root> element, and a notice says so.

{"a": 1, "b": 2}

Common errors and solutions

is not a valid XML name. Names start with a letter or _ and contain no spaces.
Rename the key shown, for example replace spaces with _ or add a letter before a leading digit.
Expected double-quoted property name
The input is not strict JSON. Remove trailing commas and comments first.

FAQ

How do I set the root element name?
Use an object with one key, such as {"catalog": {...}}. That key becomes the root element.
Is an XML declaration added?
Yes. The output starts with <?xml version="1.0" encoding="UTF-8"?>.
Is the JSON uploaded?
No. It is converted in your browser.

Related tools

  • XML to JSON converter

    Convert XML to JSON in the browser. Attributes become @ keys, repeated elements become arrays, and invalid XML is reported with its line and column.

  • JSON formatter

    Validate JSON, then pretty-print it with 2 or 4 spaces or minify it. Invalid JSON produces an error and leaves the output empty.

  • JSON validator

    Check JSON syntax in the browser. Errors give a line and column, and duplicate keys that JSON.parse would silently drop are reported.