Paste JSON and get well-formed, indented XML as you type.
Paste JSON, upload a .json file or drop one here.
Updates as you type. Copy it or download a .xml file.
Converting…
This free JSON to XML converter turns a JSON document into well-formed, indented XML. Paste an API response, a config file or an export from a database, and the XML version appears right away, with your key order and nesting intact. There is nothing to install and no sign-up, and because the conversion runs in your browser, your data is never uploaded.
JSON and XML model data differently. JSON has objects, arrays and typed values; XML has elements, attributes and text, and requires a single root element. The converter bridges the two with a small set of predictable rules, described below, so you can feed the result to a SOAP service, an RSS or sitemap tool, an enterprise integration or any other system that still expects XML.
.json file. You can also drag a file onto the editor.<?xml ... ?> line.data.xml.Objects become nested elements, the array becomes two <tags> elements, the @_id key becomes an attribute, and the ampersand in the title is escaped. The null value turns into an empty <stock/> element.
{
"book": {
"@_id": "b1",
"title": "Dune & Co",
"tags": ["sci-fi", "classic"],
"price": 9.99,
"stock": null
}
}<?xml version="1.0" encoding="UTF-8"?>
<root>
<book id="b1">
<title>Dune & Co</title>
<tags>sci-fi</tags>
<tags>classic</tags>
<price>9.99</price>
<stock/>
</book>
</root>| JSON | XML output | Notes |
|---|---|---|
{ } object | Nested child elements | An empty object is written <name/>. |
[ ] array | Repeated elements named after the key | Top-level and nested arrays use <item>; an empty array writes nothing. |
| string | Escaped text content | Whitespace and line breaks are kept as they are. |
| number, boolean | Text content | Written as JSON would write them: 9.99, true, 1e+21. |
null | <name/> | An empty element, the same as an empty string. |
@_name | name="..." | An attribute on the parent element. |
#text | Text content of the parent element | Use it together with attributes or child elements. |
A JSON document can be an object, an array or a single value, but XML always needs exactly one root element. The converter wraps whatever you paste in <root>; set the Root element option to use a more meaningful name such as catalog or response. A top-level array becomes a list of <item> children under that root, and a bare value such as 42 becomes <root>42</root>.
XML has no array type, so a list is written as the same element repeated. With "user": [{ "id": 1 }, { "id": 2 }] you get two <user> elements. Arrays inside arrays have no key to name them, so each inner list becomes an element holding <item> children. Because empty arrays write no elements at all and a one-item array looks like a single element, converting the XML back to JSON does not always restore the original array shape.
Keys that start with @_ are written as attributes of the element they belong to, and the key #text holds its text. So { "note": { "@_lang": "en", "#text": "Hi" } } becomes <note lang="en">Hi</note>. These are the same names the XML to JSON converter produces, so JSON that came from XML converts back to the same elements and attributes. When an element has both text and child elements, the text is written first and the converter does not re-indent it, because whitespace in mixed content can be significant.
JSON keys can be any string, but XML element and attribute names cannot contain spaces or most symbols and cannot start with a digit. The converter replaces every character other than letters, digits, _, -, . and : with an underscore, and adds a leading underscore when the name does not start with a letter or underscore. An empty key becomes _. If two keys end up with the same name, both are kept as repeated elements.
| JSON key | XML name |
|---|---|
first name | first_name |
2nd | _2nd |
price ($) | price____ |
soap:Body | soap:Body |
The characters &, <, >, double quotes and apostrophes are escaped in both text and attribute values, so the output stays well-formed no matter what your strings contain. Control characters that XML 1.0 forbids, such as \u0000, are removed. Colons are kept in names so prefixed names such as soap:Body pass through, but the converter does not add namespace declarations; include them yourself as @_xmlns:soap attributes if your consumer needs them.
To go the other way, use the XML to JSON converter. If you prefer a more human-friendly config format, try the JSON to YAML converter, or flatten an array of records with the JSON to CSV converter. Need sample JSON to experiment with? Create some with the JSON Generator, validate its structure with the JSON Schema Generator, or read how other serialization formats compare in Protobuf vs JSON.
Paste your JSON into the JSON Input editor, or upload a .json file. The XML appears in the output editor as you type, wrapped in a root element. Copy it, or click Download to save it as data.xml.
An XML document must have exactly one top-level element, while JSON can start with an object, an array or a plain value. The converter wraps your data in a root element named root by default. Type another name in the Root element field to change it.
An array under a key becomes repeated elements with that key's name, so "tags": ["a", "b"] gives two <tags> elements. A top-level array, or an array inside an array, uses <item> elements. Empty arrays produce no elements.
Start the key with @_ and the converter writes it as an attribute, so "@_id": "7" becomes id="7" on the parent element. Use the key #text for the element's text content. This is the same convention the XML to JSON converter produces.
Characters that XML names cannot contain, such as spaces and symbols, are replaced with an underscore, and a name that starts with a digit gets a leading underscore. For example, "first name" becomes <first_name> and "2nd" becomes <_2nd>.
A null value becomes an empty, self-closing element such as <discount/>. XML has no null type, so an empty string and an empty object are written the same way.
No. The conversion runs entirely in your browser with JavaScript, so your data never leaves your device.