Convert JSON to well-formed XML instantly. Free online converter — handles nested objects, arrays, and all JSON data types. No signup required.
JSON Input:
{
"user": {
"id": 101,
"name": "Alice",
"roles": [
"admin",
"editor"
],
"active": true
}
}
XML Output:
<?xml version="1.0"?> <user> <id>101</id> <name>Alice</name> <roles>admin</roles> <roles>editor</roles> <active>true</active> </user>
| JSON | XML Equivalent |
|---|---|
Object {"key":"value"} | <key>value</key> |
| Nested object | Nested child elements |
Array [1, 2, 3] | Repeated elements with same tag name |
| String, Number, Boolean | Text content (all types become text) |
| null | <key xsi:nil="true"/> |
// Simple JSON to XML converter
function jsonToXml(obj, rootTag = 'root', indent = '') {
if (Array.isArray(obj)) {
return obj.map(item => `${indent}<item>${jsonToXml(item, 'item', indent + ' ')}</item>`).join('\n');
}
if (typeof obj === 'object' && obj !== null) {
const children = Object.entries(obj)
.map(([key, val]) => `${indent} <${key}>${jsonToXml(val, key, indent + ' ')}</${key}>`)
.join('\n');
return `\n${children}\n${indent}`;
}
return String(obj);
}
const json = { name: 'Alice', age: 30 };
const xml = `<?xml version="1.0"?>\n<root>${jsonToXml(json)}</root>`;
// For production: use xml2js library
// npm install xml2js
import { Builder } from 'xml2js';
const builder = new Builder();
const xml = builder.buildObject(json);
import json
import dicttoxml # pip install dicttoxml
with open('data.json') as f:
data = json.load(f)
xml_bytes = dicttoxml.dicttoxml(data, custom_root='root', attr_type=False)
print(xml_bytes.decode())
# Or using xmltodict:
import xmltodict
# xml → json: json.dumps(xmltodict.parse(xml_string))
# json → xml: xmltodict.unparse(json_dict, pretty=True)
Yes. JSON Web Tools includes an XML to JSON converter. Paste your XML and get JSON output instantly — the tool handles attributes, namespaces, and mixed content.
JSON arrays become repeated XML elements with the same tag name. For example, ["a","b","c"] under key items becomes <items>a</items><items>b</items><items>c</items>. XML has no native array concept, so this is the standard approach.
XML has no type system — all values are text. The number 42 becomes the string "42" in XML. When converting back from XML to JSON, you need to apply type coercion to restore numbers and booleans from their string representations.
Free, instant, private — no signup required.
JSON and XML represent the same data in different formats. XML is still required by many SOAP APIs, enterprise systems, and document standards like XSLT, SVG, and RSS.
// JSON Input
{
"user": {
"id": 1,
"name": "Alice",
"roles": ["admin", "user"]
}
}
<!-- XML Output -->
<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<id>1</id>
<name>Alice</name>
<roles>
<item>admin</item>
<item>user</item>
</roles>
</user>
</root>
| JSON | XML Equivalent | Example |
|---|---|---|
| Object {} | <element>...</element> | Nested XML elements |
| Array [] | Repeated child elements | Or wrapped in a container |
| string | Text node | <name>Alice</name> |
| number | Text node | <id>1</id> |
| boolean | Text node | <active>true</active> |
| null | Empty or xsi:nil | <val xsi:nil="true"/> |
| key | Element name | Attribute or child element |
# Using xmltodict library
import json, xmltodict
with open("data.json") as f:
data = json.load(f)
xml_str = xmltodict.unparse({"root": data}, pretty=True)
print(xml_str)
Understanding how JSON types map to XML elements helps you predict the output and handle edge cases correctly.
// Input JSON
{
"order": {
"id": "ORD-123",
"customer": "Alice",
"items": [
{"name": "Widget", "qty": 2, "price": 9.99},
{"name": "Gadget", "qty": 1, "price": 24.99}
],
"total": 44.97
}
}
<!-- Output XML -->
<?xml version="1.0" encoding="UTF-8"?>
<order>
<id>ORD-123</id>
<customer>Alice</customer>
<items>
<item>
<name>Widget</name>
<qty>2</qty>
<price>9.99</price>
</item>
<item>
<name>Gadget</name>
<qty>1</qty>
<price>24.99</price>
</item>
</items>
<total>44.97</total>
</order>
// Node.js with js2xmlparser
const js2xmlparser = require('js2xmlparser');
const result = js2xmlparser.parse('order', jsonData);
console.log(result);
# Python with dicttoxml
import json, dicttoxml
data = json.loads(json_string)
xml_bytes = dicttoxml.dicttoxml(data, custom_root='root', attr_type=False)
xml_str = xml_bytes.decode('utf-8')
| Use Case | XML | JSON |
|---|---|---|
| SOAP web services | ✓ Required | ✗ Not supported |
| REST APIs | ✓ Possible | ✓ Preferred |
| RSS/Atom feeds | ✓ Standard | ✗ Not standard |
| HTML documents | ✓ Related (XHTML) | ✗ |
| Android resources | ✓ Standard | ✗ |
| Configuration files | ✓ Common | ✓ Common |
| Database storage | ✗ Rarely | ✓ Native JSON columns |
| JavaScript apps | ✓ Possible | ✓ Native |
Also useful: JSON to CSV | JSON to YAML | JSON vs XML Guide | JSON Formatter