JSON to XML

Convert JSON to XML with root-name and attribute options.

The JSON to XML converter turns a JSON document into indented XML under a root element you name. Arrays become repeated elements, keys beginning with @_ become attributes, and special characters are escaped. It is a quick way to feed JSON data to a system that expects XML.

How does JSON map to XML?

JSON and XML describe similar trees but have no official one-to-one mapping, so every converter makes choices. XML needs a single root element, so this tool wraps your data in the element named in Root element. Each JSON key becomes a child element and its value becomes the element's text or its nested children. Because XML has no array type, an array is written as the same element repeated once per item. Attributes are an XML concept without a JSON equivalent, so by convention a key that starts with @_ is written as an attribute of the parent, and a key named #text holds the text of an element that also has attributes. Element names must be valid XML names, so characters such as spaces are replaced with underscores.

How to use JSON to XML

  1. Paste the JSON Paste valid JSON into the JSON box. The XML appears as soon as the input parses.
  2. Set the root element Type the name of the wrapping element in Root element. The default is root.
  3. Choose the layout Pick Indent (2 spaces, 4 spaces or Tab) and tick or untick XML declaration.
  4. Copy or download Copy the XML from the XML box, or use Download to save it as output.xml.

Frequently asked questions

How are arrays converted?

An array under a key becomes that element repeated once per item. For example {"tags":["a","b"]} gives two <tags> elements.

How do I produce attributes?

Prefix the key with @_ . A key "@_id":"7" on an object becomes id="7" on its element. Use the key #text for the text content of an element that also has attributes.

Why does my array at the top level give several root elements?

XML allows only one root element, but a top-level array is written as the root element repeated for each item. Wrap the array in an object to get a single root.

Are numbers and booleans typed in the XML?

No. XML text has no types, so values are written as their text, such as 5 or true.

Is my data sent to a server?

No. The conversion happens in the page and the input is not sent anywhere.