JSON to XML Converter
Convert JSON to well-formed XML: keys become elements, arrays repeat their element, "@" keys become attributes. Choose the root name and indentation.
Runs in your browser. What you enter is kept for 30 days to improve Toolgrid, then deleted.
How to use the JSON to XML Converter
- 1 Paste your JSON.
- 2 Set the root element name, the name for items of a top-level array and the indentation.
- 3 Copy the XML or download it as an .xml file.
About the JSON to XML Converter
JSON and XML both describe nested data, but XML needs a single root element and has no arrays. The converter wraps your data in a root element (named "root" unless you choose another name), turns every key into an element, and writes each item of an array as a repeated element with the key's name.
Keys that start with "@" become attributes of their element and a "#text" key becomes its text, which is the convention used by most XML-to-JSON converters, including ours. That makes round trips between the two formats possible. Characters such as < and & are escaped, and keys that aren't valid XML names (for example "1st item") are turned into valid ones.
null values become empty elements (<note/>), and true, false and numbers are written as text, because XML itself has no data types. If you need typed values, describe them in an XML Schema (XSD) for the receiving system.
Frequently asked questions
How are JSON arrays converted?
Each item becomes an element with the array's key as its name: {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag>. A top-level array is wrapped in the root element with "item" elements.
Can I create XML attributes?
Yes: prefix the key with @. {"book": {"@id": "1", "title": "X"}} becomes <book id="1"><title>X</title></book>.
What happens to invalid element names?
Characters that aren't allowed are replaced by underscores, and a name that starts with a digit or "xml" gets an underscore in front, so the output is always well-formed.
Is the XML declaration required?
No, it's optional for UTF-8 documents, but many systems expect it. Uncheck the option to leave it out, for example when embedding the XML in another document.