JSON to XML Converter
Paste JSON — get valid XML output instantly. Nothing leaves your browser.
How to convert JSON to XML
- Paste your JSON object into the input field — a single root object whose keys become XML element names.
- Click "Convert" — the formatted XML output appears instantly with proper indentation and an XML declaration.
- Switch to "XML → JSON" using the toggle above if you need the reverse direction.
- Click "Copy" or "Download .xml" to use the output in your system, API, or configuration file.
- Use @attributes in your JSON to produce XML element attributes — see the mapping reference below.
How the JSON to XML converter works
The converter traverses the JSON object recursively and maps each key-value pair to an XML element. String and number values become element text content. Nested objects become child elements. Arrays are expanded into repeated sibling elements with the parent key as the tag name. The special key @attributes produces XML attributes on the parent element; the special key #text produces mixed text content alongside attributes. The output includes an XML declaration and is indented for readability.
The @attributes convention makes the conversion reversible — JSON produced by the XML to JSON converter can be converted back to XML and produce the same structure. The conversion runs entirely in your browser — no data leaves your machine.
// Input JSON:
{
"users": {
"user": [
{ "@attributes": { "id": "1" }, "name": "Alice", "city": "Kyiv" },
{ "@attributes": { "id": "2" }, "name": "Bob", "city": "Lviv" }
]
}
}
// Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="1">
<name>Alice</name>
<city>Kyiv</city>
</user>
<user id="2">
<name>Bob</name>
<city>Lviv</city>
</user>
</users>Who uses JSON to XML conversion
JSON is the primary data format for modern web APIs. XML is the required format for enterprise integrations, legacy systems, and certain configuration tools. Converting JSON to XML bridges these two generations of technology.
- SOAP API integration — building request payloads for SOAP or XML-RPC web services from JSON data in a JavaScript or Node.js application.
- Enterprise message bus — formatting messages for systems that use XML-based message formats (JMS, MQ, ESB, EDI).
- Configuration file generation — creating XML config files (Maven pom.xml, Spring beans, Android resources) from JSON-based build data.
- Data export to legacy systems — converting modern API responses to XML for import into ERP, CRM, or accounting systems that require XML.
- Sitemap generation — building XML sitemaps from a JSON list of URLs and metadata.
- Office document creation — generating OOXML fragments (Excel, Word) from structured JSON data for reporting pipelines.
JSON to XML mapping conventions
The converter follows a set of mapping conventions for the JSON-to-XML direction. Understanding these conventions lets you structure your JSON input to produce exactly the XML output you need.
| JSON input | XML output | Notes |
|---|---|---|
| "tag": "text" | <tag>text</tag> | String value → text content |
| "tag": 42 | <tag>42</tag> | Number value → text content (stringified) |
| "tag": true | <tag>true</tag> | Boolean value → text content |
| "tag": null | <tag/> | null → self-closing empty element |
| "tag": { "child": "v" } | <tag><child>v</child></tag> | Object → child elements |
| "tag": ["a", "b"] | <tag>a</tag><tag>b</tag> | Array → repeated sibling elements |
| "@attributes": { "id": "1" } | id="1" on parent element | @attributes → XML attributes |
| "#text": "content" | text content alongside attributes | #text → mixed element text content |
When to convert JSON to XML — and when to keep JSON
Convert to XML when:
- Target system requires XML — SOAP services, enterprise message buses, and legacy APIs that only accept XML-encoded payloads.
- Document markup is needed — XML supports mixed content (text interleaved with elements) used in document formats like DocBook, TEI, and OOXML.
- Configuration files must be XML — Maven, Spring, Android resources, and many Java ecosystem tools use XML as their config format.
- XSLT transformation pipeline — XSLT processing requires XML input; the JSON needs to become XML before it can be transformed.
- Schema validation is required — XML Schema (XSD) and RelaxNG provide strict structural validation that JSON Schema does not match in all enterprise contexts.
Keep JSON when:
- Target is a REST API or JavaScript application — JSON.parse() is native; XML adds unnecessary parsing overhead.
- Payload size matters — JSON is typically 20–40% smaller than equivalent XML due to the absence of closing tags.
- Data has arrays of uniform objects — JSON arrays are cleaner than repeated XML elements with no semantic distinction.
- NoSQL databases are the destination — MongoDB, Firestore, and DynamoDB store JSON-like documents natively.
Building valid XML: element names and special characters
XML has stricter naming and encoding rules than JSON. When structuring the JSON input for conversion, keep these XML constraints in mind to avoid invalid output:
- Element names must start with a letter or underscore — JSON keys that start with a digit (like "1item") produce invalid XML. Rename such keys before converting.
- No spaces in element names — JSON keys with spaces ("first name") cannot become valid XML tags. Use camelCase or underscore-separated keys instead.
- Special characters in text content are escaped — the converter automatically escapes &, <, >, ", and ' in text values to &, <, >, ", and '.
- The JSON root must be a single object — JSON arrays at the root level are not valid because XML requires exactly one root element. Wrap arrays in an object: { "items": [...] }.
- Attribute values are strings — the @attributes object should contain only string or number values; nested objects inside @attributes are not valid.
// JSON with @attributes for element attributes
// and #text for mixed content:
{
"product": {
"@attributes": { "id": "P001", "currency": "USD" },
"name": "Wireless Headphones",
"price": {
"@attributes": { "sale": "true" },
"#text": "49.99"
},
"tags": ["audio", "wireless", "bluetooth"]
}
}
// Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<product id="P001" currency="USD">
<name>Wireless Headphones</name>
<price sale="true">49.99</price>
<tags>audio</tags>
<tags>wireless</tags>
<tags>bluetooth</tags>
</product>