JSON to XML Converter

Convert any JSON document into indented, well-formed XML with predictable rules for arrays and attributes.

Loading tool…

About the JSON to XML

Mapping rules: each key becomes an element; an array under a key becomes that element repeated, so {"tag": ["a", "b"]} gives <tag>a</tag><tag>b</tag>. Keys starting with @ become attributes and a #text key becomes the element's text. These are the same conventions the XML to JSON converter produces, so a round trip keeps attributes.

XML needs a single root element. If the JSON is an object with exactly one key, like {"catalog": {...}}, that key is used as the root. Otherwise the output is wrapped in the element named in Root, and items of a top-level array use the Row name. null and empty strings become self-closing elements.

Keys that are not valid XML names are sanitised: first name becomes first_name and 1st becomes _1st. Text and attribute values are escaped. XML has no data types, so true and 42 become plain text.

Example: [{"id": 1}, {"id": 2}] with the default names becomes <root><row><id>1</id></row><row><id>2</id></row></root>.

How to use it

  1. Paste JSON or open a .json file.
  2. Set the root and row element names if needed.
  3. Copy the XML or download converted.xml.

Frequently asked questions

How do I create XML attributes from JSON?
Prefix the key with @: {"book": {"@id": "bk101", "title": "XML"}} gives <book id="bk101"><title>XML</title></book>.
What happens to nested arrays?
An array inside an array has no key to name its elements, so its items are wrapped in <item> elements.
Is the conversion lossless?
Structure is kept, but XML has no types: numbers, booleans and null become text or empty elements.

Related tools