What it does
This tool converts JSON data into XML. Objects become elements, arrays become repeated elements, strings, numbers and booleans become text, and null becomes an empty element. Keys that start with @ turn into attributes and a #text key sets an element’s text, which mirrors the format produced by the XML to JSON converter, so data can make a round trip.
How to use
- Paste JSON into the Input box, upload a
.jsonfile, or click Sample. - The XML appears on the right as you type. Invalid JSON is reported with its position.
- Pick an Indent style, set the Root element name, change the Attribute key prefix, and choose whether to add the
<?xml ?>declaration. - Copy the XML or download it as an
.xmlfile.
Example
{ "book": { "@id": "bk101", "title": "XML Guide", "tags": ["xml", "json"], "price": 44.95 } }
becomes
<?xml version="1.0" encoding="UTF-8"?>
<book id="bk101">
<title>XML Guide</title>
<tags>xml</tags>
<tags>json</tags>
<price>44.95</price>
</book>
Notes
Special characters are escaped (&, <, > in text and also " in attributes), so the output can be loaded by any XML parser. JSON has no way to express namespaces, comments or CDATA, so none are generated.
FAQ
› How do I create XML attributes from JSON?
Start the key with "@". {"book": {"@id": "bk101", "title": "Guide"}} becomes <book id="bk101"><title>Guide</title></book>. You can change the prefix or clear it to turn every key into an element.
› How are JSON arrays converted?
An array repeats its parent element once per item, so {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag>. A top-level array, or an array directly inside another array, uses <item> elements.
› What happens to keys that are not valid XML names?
Spaces and symbols are replaced with underscores, and names that start with a digit or with "xml" get a leading underscore, so the output is always well-formed.
› Where does the root element come from?
If the JSON object has exactly one key, that key becomes the root. Otherwise everything is wrapped in the root element name from the options, "root" by default.