JSON to XML Converter
Paste JSON and get indented XML with a declaration at the top. Objects become elements, arrays become repeated tags, and keys that start with @ become attributes. Prettify renames keys that are not valid XML names and tells you which ones. Everything runs in your browser.
How JSON maps to XML
XML needs exactly one root element, and JSON does not. Prettify chooses the root for you. If your JSON is an object with a single key, that key becomes the root element. If it has several keys, Prettify wraps them in an element named root.
A top-level array, or an array inside an array, wraps its items in item elements. An array under a key repeats that key as an element once per entry, so "tags": ["rush", "gift"] becomes two tags elements.
Key features
The output follows fixed rules, so you can predict it and convert it back. Prettify applies the same rules to every document and reports each change it had to make.
- The output starts with an XML declaration and uses two-space indentation.
- A key that starts with @ becomes an attribute, and a "#text" key becomes the text of the element.
- A null value or an empty string becomes a self-closing element, such as <note/>.
- The characters &, <, and > are escaped in text, and quotes are escaped in attribute values.
- A key that is not a valid XML name is renamed, and the warning lists the renamed keys.
- Numbers and booleans are written as text, such as 84.5 and true.
- Prettify warns about single-item arrays and about numbers that may lose precision.
How to convert JSON to XML
Convert in the box on this page, then continue in the editor. The box reads documents up to 512 KB. If the JSON has an error, the panel shows the line and column, and the button reads "Fix it in the editor".
- Paste your JSON into the box labeled "Paste your JSON", or select "Try an example".
- Read the XML in the result panel. The warning under the summary lists renamed keys and other changes.
- Select Copy to put the XML on the clipboard, or select Download to save it as prettify.xml.
- Select "Open in full editor". The editor opens at /app/editor with the XML in the Raw view.
- Switch to the Tree view in the editor to check the element structure.
- For a larger file, open the JSON in the editor, select Convert in the Transform group of the toolbar, and pick XML.
Worked example: an order
The JSON below is an object with one top-level key, so order becomes the root element. The block after it is the XML that Prettify produces.
The @id key becomes the id attribute. The tags array repeats as two tags elements. The key "ship to" has a space and "2fa" starts with a digit, so Prettify renames them to ship_to and _2fa. It reports both renames in the warning. The null note becomes the self-closing note element, and the number 84.5 becomes text.
{
"order": {
"@id": "A-1001",
"customer": "Dana Reyes",
"tags": ["rush", "gift"],
"ship to": {
"city": "Austin",
"2fa": true
},
"total": 84.5,
"note": null
}
}
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1001">
<customer>Dana Reyes</customer>
<tags>rush</tags>
<tags>gift</tags>
<ship_to>
<city>Austin</city>
<_2fa>true</_2fa>
</ship_to>
<total>84.5</total>
<note/>
</order>Common uses
Some systems still accept only XML. Converting from JSON lets you keep working in the format you already know, and then send the result to wherever XML is required.
- Build a payload for an XML endpoint from JSON you already have.
- Turn JSON test data into XML fixtures.
- Feed JSON data to a tool that reads only XML, such as an older import job.
- Learn how a JSON shape maps to XML before you design a schema.
- Round trip a document: convert to XML, edit it, and convert back to JSON.
What to check in the output
XML text has no types, so numbers and booleans come back as strings if you convert the XML to JSON again. An array with one item becomes one element, so it reloads as a single value. Prettify warns you when this happens.
Element and attribute names cannot hold spaces, and they cannot start with a digit, a dot, or a hyphen. Prettify replaces a bad character with an underscore and adds a leading underscore where a name starts badly. The warning lists up to five renames and counts the rest.
Numbers outside the safe range of JavaScript lose precision in XML, because the converter turns them into native numbers first. Prettify warns about this too. If a long ID must stay exact, keep it as a string in the JSON.
Frequently asked questions
Is the JSON to XML converter free?
Yes. Converting JSON to XML and copying or downloading the result is free and needs no account. Nothing in this conversion needs Pro.
How do I choose the name of the root element?
Give the JSON a single top-level key, and that key becomes the root element. With several top-level keys, or with a top-level array, Prettify uses root as the root element name.
How do I write an attribute in the JSON?
Start the key with @. A key such as "@id" becomes the attribute id on its parent element. To give an element both attributes and text, put the text under a "#text" key.
Is my JSON uploaded to convert it?
No. The converter runs on your device. Your JSON goes nowhere unless you create a share link, which is a choice you make.
Does the XML keep the order of my keys?
Yes. Elements follow the order of the keys in your JSON. The items of an array keep their order and appear together at the position of their key.
Can I get the JSON back from the XML?
Yes. Use the XML to JSON page or the Convert menu in the editor. Attributes return as @ keys, but a renamed key keeps its new name, and every value returns as a string.