Boneyard Tools

JSON to XML Converter

Paste a JSON document and this converter returns well-formed XML with each object key as an element, arrays expanded into repeated tags, and the five XML special characters escaped for you. You can rename the root element and switch between two spaces, four spaces, a tab or compact output. The whole conversion happens in your browser, so nothing is uploaded.

How to convert JSON to XML

  1. Paste or type your JSON into the JSON input box, or press Load sample.
  2. Set the Root element name that will wrap the whole document (root by default).
  3. Choose an Indent of 2 spaces, 4 spaces, a tab or Compact for no line breaks.
  4. Read the generated XML in the output box, with the declaration line on top.
  5. Copy the XML or download it as data.xml for use elsewhere.

Examples

Object keys become elements

{"name":"Ada","age":36}
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>Ada</name>
  <age>36</age>
</root>

An array becomes repeated tags

{"name":"Ada","skills":["Math","Engineering"]}
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>Ada</name>
  <skills>Math</skills>
  <skills>Engineering</skills>
</root>

A top-level array uses item elements

[1,2,3]
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <item>1</item>
  <item>2</item>
  <item>3</item>
</root>

Frequently asked questions

Is my data uploaded anywhere?

No. The conversion runs entirely in your browser using client-side JavaScript, so your JSON never leaves your device and nothing is logged on a server.

How are JSON arrays turned into XML?

Each array item becomes a repeated element that reuses the key it sat under, since XML has no native array type. So a skills array of two strings becomes two sibling <skills> elements rather than one wrapper element.

What happens to a top-level array with no key?

A JSON document whose root is an array has no key to name its items, so each element is wrapped in a generic <item> tag inside the root element. This keeps the output valid even when the outermost value is a list.

Are special characters escaped?

Yes. The characters &, <, > and the double quote are replaced with their XML entities (&amp;, &lt;, &gt; and &quot;), so text containing angle brackets or ampersands does not break the markup.

What happens to keys that are not valid XML names?

Spaces and other illegal characters in a key become underscores, and a key that begins with a digit, a dot or a hyphen is prefixed with an underscore, because XML element names cannot start with those.

How are null values represented?

A JSON null becomes an empty element such as <note></note>. The tag is kept so the structure stays intact, but it carries no text content.

Are values written as attributes or as text?

Everything is written as element text content, never as XML attributes. Numbers and booleans are converted to their string form, so true becomes the text true and 36 becomes the text 36 inside their tags.

Can I change the root element or remove indentation?

Yes. Type any name into the Root element field, and pick 2 spaces, 4 spaces, a tab or Compact from the Indent menu. Compact output drops all line breaks and produces a single dense line.

Does it convert XML back into JSON?

No, this tool only goes one direction, from JSON to XML. For the reverse, or for related formats, try a dedicated XML-to-JSON tool or the JSON to CSV and JSON to YAML converters.

Learn more

Related tools