JSON to XML

Convert JSON to XML format

Try an example

JSON Input

XML Output

Runs locally · Safe to paste secrets
XML will appear here…

What is JSON to XML Conversion?

JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) are the two dominant data interchange formats in software development. JSON uses key-value pairs and arrays in a compact syntax, while XML wraps data in opening and closing tags with optional attributes. Converting JSON to XML means translating JSON's structural primitives — objects, arrays, strings, numbers, booleans, and null — into a well-formed XML document with matching element nesting.

XML remains the required format in many enterprise systems, government APIs, SOAP web services, and industry standards like HL7 (healthcare), FpML (finance), and XBRL (financial reporting). When your application produces JSON but the downstream consumer expects XML, a JSON to XML converter handles the translation without manual restructuring. The conversion follows predictable mapping rules: JSON objects become XML elements, array items become repeated sibling elements, and primitive values become text nodes.

There is no single RFC or W3C standard that defines how JSON maps to XML. Different libraries produce different output for the same input. The most common convention (used by this tool) wraps the entire document in a configurable root element, converts each JSON key to an XML child element, and represents array items as repeated elements with the same tag name. Understanding these mapping rules matters when the receiving system enforces a specific XML schema (XSD).

Why Use an Online JSON to XML Converter?

Writing XML by hand from a JSON source is tedious and error-prone. Mismatched tags, forgotten closing elements, and incorrect nesting produce documents that fail schema validation. A converter handles the structural translation automatically.

Convert Instantly in Your Browser
Paste JSON, get well-formed XML in milliseconds. No server round-trip, no CLI setup, no dependency installation. The conversion runs entirely in JavaScript on your device.
🔒
Keep Sensitive Data Private
Your JSON input never leaves the browser tab. All parsing and XML generation happen client-side, making it safe to convert payloads containing API keys, tokens, or production data.
📋
No Account or Login Required
Open the page, paste your JSON, and copy the XML output. No sign-up forms, email verification, or usage limits standing between you and your converted data.
🌳
Handle Nested Structures Automatically
Deeply nested objects, mixed arrays, and null values all convert correctly. The tool preserves the full hierarchy of your JSON input in the resulting XML tree.

JSON to XML Use Cases

SOAP Web Service Integration
Your REST API returns JSON, but a partner's SOAP endpoint requires XML request bodies. Convert the JSON payload to XML before wrapping it in a SOAP envelope.
Enterprise Data Exchange
Legacy ERP and CRM systems often accept only XML imports. Convert JSON exports from modern tools into XML feeds that match the expected schema.
CI/CD Pipeline Configuration
Some build tools (Maven, Ant, MSBuild) use XML configuration files. Generate XML config fragments from JSON parameter files during automated builds.
QA Test Data Preparation
Generate XML test fixtures from JSON datasets. Quickly produce valid XML documents for testing XML parsers, XSLT transformations, or XPath queries.
Data Pipeline Format Bridging
ETL pipelines that ingest XML can receive data from JSON-producing APIs. Convert intermediate JSON results to XML before loading into the XML-based processing stage.
Learning XML Structure
Students studying XML can paste familiar JSON structures and see the equivalent XML representation. This makes tag nesting, element hierarchy, and document structure concrete.

JSON to XML Mapping Rules

Because no universal standard governs JSON-to-XML conversion, different tools produce different output. The table below shows the mapping conventions used by this converter and most popular libraries (js2xmlparser, xmlbuilder, fast-xml-parser). The repeated-sibling convention for arrays became dominant because it mirrors how XML schemas naturally model collections — each item is a first-class element rather than a wrapped child — and it integrates cleanly with XPath queries and XSLT transforms.

JSON TypeJSON ExampleXML Output
Object{"name": "Alice"}<name>Alice</name>
Nested object{"user": {"age": 30}}<user><age>30</age></user>
Array{"colors": ["red", "blue"]}<colors>red</colors><colors>blue</colors>
String"hello"<root>hello</root>
Number42<root>42</root>
Booleantrue<root>true</root>
Nullnull<root/>
Empty object{}<root/>
Empty array[](no child elements)

Code Examples

Below are runnable snippets for converting JSON to XML in three environments. Each example produces well-formed XML from a sample JSON object.

JavaScript (Node.js)
import { create } from 'xmlbuilder2';

const json = {
  order: {
    id: 1024,
    items: [
      { sku: "A1", qty: 2 },
      { sku: "B3", qty: 1 }
    ],
    shipped: false
  }
};

const xml = create({ version: '1.0' })
  .ele(json)
  .end({ prettyPrint: true });

console.log(xml);
// → <?xml version="1.0"?>
// → <order>
// →   <id>1024</id>
// →   <items>
// →     <sku>A1</sku>
// →     <qty>2</qty>
// →   </items>
// →   <items>
// →     <sku>B3</sku>
// →     <qty>1</qty>
// →   </items>
// →   <shipped>false</shipped>
// → </order>
Python
import json
import xmltodict

data = {
    "order": {
        "id": 1024,
        "items": [
            {"sku": "A1", "qty": 2},
            {"sku": "B3", "qty": 1}
        ],
        "shipped": False
    }
}

# xmltodict.unparse expects a single root key
xml = xmltodict.unparse(data, pretty=True)
print(xml)
# → <?xml version="1.0" encoding="utf-8"?>
# → <order>
# →   <id>1024</id>
# →   <items>
# →     <sku>A1</sku>
# →     <qty>2</qty>
# →   </items>
# →   <items>
# →     <sku>B3</sku>
# →     <qty>1</qty>
# →   </items>
# →   <shipped>false</shipped>
# → </order>
Go
package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
)

type Item struct {
	SKU string `json:"sku" xml:"sku"`
	Qty int    `json:"qty" xml:"qty"`
}

type Order struct {
	XMLName xml.Name `xml:"order"`
	ID      int      `json:"id" xml:"id"`
	Items   []Item   `json:"items" xml:"items"`
	Shipped bool     `json:"shipped" xml:"shipped"`
}

func main() {
	raw := `{"id":1024,"items":[{"sku":"A1","qty":2},{"sku":"B3","qty":1}],"shipped":false}`

	var order Order
	json.Unmarshal([]byte(raw), &order)

	out, _ := xml.MarshalIndent(order, "", "  ")
	fmt.Println(xml.Header + string(out))
	// → <?xml version="1.0" encoding="UTF-8"?>
	// → <order>
	// →   <id>1024</id>
	// →   <items>
	// →     <sku>A1</sku>
	// →     <qty>2</qty>
	// →   </items>
	// →   ...
}

Frequently Asked Questions

Is JSON to XML conversion lossless?
Structurally, yes — every JSON value maps to an XML element or text node. However, XML does not natively distinguish between numbers, booleans, and strings the way JSON does. The value 42 in JSON becomes the text content "42" in XML. If the receiving system relies on XML Schema (XSD) type declarations, it can recover the original types during parsing. Without a schema, the type information is effectively lost in the converted document.
How are JSON arrays converted to XML?
Each array item becomes a sibling XML element with the same tag name. For example, the JSON array "colors": ["red", "blue"] produces two elements: &lt;colors&gt;red&lt;/colors&gt; and &lt;colors&gt;blue&lt;/colors&gt;. Some converters wrap arrays in a parent element (e.g., &lt;colorsList&gt;), but the repeated-sibling approach is more common and matches the convention used by JAXB, Jackson, and fast-xml-parser.
What happens to null values in the conversion?
A JSON null typically converts to an empty XML element — for example, "middle_name": null becomes &lt;middle_name/&gt;. Some libraries add an xsi:nil="true" attribute to signal an explicit null, which is useful when the target system validates against an XSD schema. This converter outputs a self-closing empty element by default.
Can I convert XML back to JSON?
Yes, but the round-trip is not always symmetric. XML features like attributes, processing instructions, comments, mixed content, and namespaces have no direct JSON equivalent. Converting XML to JSON and back to XML can produce a structurally different document. If you need XML-to-JSON conversion, use a dedicated XML to JSON converter that preserves attributes and namespaces.
How do I handle JSON keys that are not valid XML element names?
XML element names cannot start with a digit, contain spaces, or include most special characters. If your JSON has a key like "2024-data" or "first name", the converter must sanitize it — typically by prefixing an underscore or replacing invalid characters with underscores. Check your converter's output and adjust key names in the source JSON if the resulting XML needs to pass XSD validation.
What is the maximum JSON size this tool can handle?
The converter runs in your browser's JavaScript engine, so the practical limit depends on available memory. Most modern browsers handle JSON documents up to 50-100 MB without issues. For files larger than that, use a streaming converter like Python's xmltodict or a command-line tool that processes the data incrementally rather than loading it all into memory.
Is the output XML well-formed or valid?
The output is always well-formed XML — tags are properly nested, special characters are escaped, and the document has a single root element. Whether the output is valid depends on the target schema (XSD or DTD). Well-formedness is a structural guarantee; validity requires that the element names, nesting order, and content types match a specific schema definition.