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
- Paste JSON into the JSON box. A sample with a person, name and age is already there.
- If the JSON has a syntax error, the error text appears in red instead of the output.
- Otherwise the XML box shows the declaration line followed by the indented markup.
- 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.