Home › JSON to XML Converter

JSON to XML Converter Online

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 to XML Conversion Example

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 to XML Mapping Rules

JSON XML Equivalent
Object {"key":"value"}<key>value</key>
Nested objectNested child elements
Array [1, 2, 3]Repeated elements with same tag name
String, Number, BooleanText content (all types become text)
null<key xsi:nil="true"/>

Convert JSON to XML in JavaScript

// 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);

Convert JSON to XML in Python

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)

When to Convert JSON to XML

Frequently Asked Questions

Can I convert XML back to JSON?

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.

What happens to JSON arrays in XML?

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.

Are JSON numbers preserved in XML?

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.

Convert JSON to XML now

Free, instant, private — no signup required.

Open JSON to XML →

Also useful: JSON to CSV | JSON to YAML | JSON vs XML Guide | JSON Formatter