Home / Data tools / JSON to XML converter

JSON to XML Converter

Paste JSON and get well-formed XML. Choose the root element, how arrays are written, and whether keys that start with @ become attributes.

How the conversion works

JSON and XML describe data differently, so a converter has to make a few choices. This tool follows common conventions you can adjust with the options above.

  • Objects become elements, and each key becomes a child element.
  • Arrays become repeated elements with the same name, or a wrapper element with item children, as you choose.
  • Attributes: a key that starts with @ becomes an XML attribute, and a key named #text becomes the text of the element.
  • null becomes an empty element, and numbers and booleans become text.
  • Special characters such as & and < are escaped for you.

Example

{"person":{"@id":"1","name":"Ann","skills":["js","php"]}}

becomes

<person id="1">
  <name>Ann</name>
  <skills>js</skills>
  <skills>php</skills>
</person>

The root element

XML needs exactly one root element. If your JSON has a single top-level key, that key becomes the root. Otherwise the data is wrapped in the root name you enter, which is root by default.

Things to know

JSON keys that are not valid XML names, such as keys with spaces or a leading digit, are cleaned up by replacing bad characters with an underscore. XML also has no data types, so the number 5 and the text 5 look the same once converted.

Going the other way? Use the XML to JSON converter. To work from a file, see JSON to XML online. For control over indentation and formatting, use JSON to XML pretty print. Not sure which format to use? Read JSON vs XML.

Frequently asked questions

How do I convert JSON to XML?

Paste your JSON into the input box. The XML appears in the output box, ready to copy or download.

How are JSON arrays converted?

By default each item becomes a repeated element with the key name. You can switch to a wrapper element with item children.

How do I create XML attributes?

Start the key with @. For example, "@id": "1" becomes id="1" on the element.

Why do I get an error?

The JSON is not valid. Common causes are trailing commas, single quotes and unquoted keys.