Convert JSON to well-formed XML instantly. Free online converter — handles nested objects, arrays, and all JSON data types. No signup required.
Convert JSON to XML →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.
Also useful: JSON to CSV | JSON to YAML | JSON vs XML Guide | JSON Formatter