Skip to content

Converter Tools

JSON to XML

Turns JSON keys and values into nested, indented XML elements with special characters escaped, useful for systems that expect XML input.

  • Free
  • No sign-up
  • Runs in your browser

Guide

Mapping JSON onto XML elements

JSON stores data in objects and arrays, while XML uses nested tagged elements. Converting means turning each key into a tag name and each value into the content between the tags.

An object becomes an element whose children are its keys. A plain value (text, number, true or false) becomes the text inside an element. An array becomes a series of repeated elements named after the key. The output begins with a standard XML declaration and is indented so it is easy to read.

For example, { "person": { "name": "Ada", "age": 32 } } produces the declaration followed by a person element containing name and age elements. When your JSON has exactly one top-level key, that key becomes the root element.

Why you might need XML output

Plenty of established systems still expect XML: shipping and payment integrations, publishing workflows, government and banking interfaces, and older enterprise software. If your data lives in JSON, for example from a modern API, you may need to hand it over as XML.

It is also useful for building sample XML payloads for testing. If you already have XML and need JSON, use XML to JSON, and the XML formatter can re-indent markup from other sources.

How to convert JSON to XML here

  1. Paste JSON into the JSON box. A sample with a person, name and age is already there.
  2. If the JSON has a syntax error, the error text appears in red instead of the output.
  3. Otherwise the XML box shows the declaration line followed by the indented markup.
  4. Click Copy or Download .xml.

The conversion is performed in your browser and nothing is uploaded. If the JSON may be malformed, check it first with the JSON validator.

How the converter keeps the XML valid

XML is stricter than JSON, so the tool adjusts a few things for you:

  • Several top-level keys: nothing is dropped. If there is more than one, or the top level is an array, everything is wrapped in a root element called root (array items become item elements).
  • Special characters: &, < and > in values are written as &, < and >, so the markup stays well-formed.
  • Invalid tag names: keys with spaces or odd characters get underscores (my key becomes my_key), and keys that start with a digit or symbol get a leading underscore.
  • null and empty objects become empty self-closing elements such as .
  • Empty arrays produce no elements, since there is nothing to repeat.

What it does not do is create XML attributes. Every value becomes a child element. Because of the renamed tags, converting back to JSON may not give exactly the original keys.

Frequently asked questions

What does the tool use as the root element?

If your JSON has a single top-level key, that key is the root. Otherwise, or if the top level is an array, everything is wrapped in a root element named root so nothing is lost.

How are arrays represented?

Each array item becomes its own element, repeated with the key's name. A key called item with three values gives three item elements in a row.

Does it escape special characters like & and <?

Yes. They are converted to &amp;, &lt; and &gt;, so the XML stays valid.

Can it create XML attributes?

No. Every JSON value becomes a child element. If you need attributes, edit the XML afterwards.