Menu

How-To Guide JSON · XML March 2026 ⏱ 7 min read

How to Convert JSON to XML Online: Step-by-Step With Examples

Not every system speaks JSON. Enterprise platforms, SOAP APIs, and regulated industries require XML. Here is exactly how the conversion works and how to do it in under 30 seconds.

Most modern development uses JSON. But not every system you integrate with speaks JSON. Enterprise platforms, SOAP APIs, legacy databases, and regulated industries often require XML. When you need to convert JSON data to XML format, doing it manually means rewriting the entire structure, slow, error-prone, and unnecessary. This guide explains how JSON maps to XML, shows a complete real-world conversion, and walks through using a free online converter.

Why Would You Need to Convert JSON to XML?

The need to convert JSON to XML is almost always driven by a system requirement, something downstream that cannot accept JSON and expects XML. Here are the four most common scenarios:

🔌
SOAP API Integrations
SOAP (Simple Object Access Protocol) requires XML for all requests and responses. Many banking, government, and healthcare systems still use SOAP. If your application receives data in JSON and needs to pass it to a SOAP endpoint, XML conversion is necessary.
🏢
Enterprise System Integration
ERP systems like SAP and Oracle, and legacy CRM platforms, commonly require XML for data import. If you are building an integration between a modern JSON API and one of these systems, your data must be in XML format before it can be accepted.
📋
Industry Data Standards
Healthcare (HL7, FHIR), financial services (FpML, SWIFT), and document publishing (DocBook) have established XML-based standards. Working in these regulated industries means working with XML. JSON is simply not an accepted format for these exchanges.
⚙️
XSLT Data Transformation
XSLT can only transform XML. If you need to restructure data using XSLT stylesheets, for report generation, data migration, or format adaptation, your source data must first be converted to XML format.

How JSON Maps to XML — The Three Rules

Understanding how JSON structures translate to XML helps you predict what the output will look like and verify that it is correct. The mapping follows three consistent rules:

JSON
{ "key": { } }
Object with nested properties
XML
<key>...</key>
Each key becomes a child element
JSON
["a", "b", "c"]
Array with multiple items
XML
<item>a</item> ×3
Repeating elements, XML has no native array
JSON
"name": "Alex"
String, number, or boolean value
XML
<name>Alex</name>
Value becomes element text content
⚡ The array difference

The most significant structural difference between JSON and XML is how arrays are represented. JSON has native array syntax: ["a", "b"]. XML does not. Array items become repeating elements, typically named after the singular form of the parent key. The data is identical; only the structural representation changes.

A Real Conversion Example

Here is a realistic API response, an order with nested customer details and a line items array, converted from JSON to XML. This is representative of the kind of data you would need to pass to an enterprise system or SOAP endpoint:

JSON Input
{ "order": { "id": "ORD-4821", "customer": "Alex Johnson", "total": 149.99, "status": "confirmed", "items": [ { "name": "Keyboard", "qty": 1, "price": 89.99 }, { "name": "Mouse", "qty": 1, "price": 60.00 } ] } }
XML Output
<?xml version="1.0" encoding="UTF-8"?> <order> <id>ORD-4821</id> <customer>Alex Johnson</customer> <total>149.99</total> <status>confirmed</status> <items> <item> <name>Keyboard</name> <qty>1</qty> <price>89.99</price> </item> <item> <name>Mouse</name> <qty>1</qty> <price>60.00</price> </item> </items> </order>

The data is identical. Notice specifically how the items array became two repeating <item> elements wrapped in an <items> parent. That is the array mapping rule in action.

✓ What stayed the same
  • All field names preserved as element names
  • All values preserved exactly
  • Nesting hierarchy maintained throughout
  • No data added, removed, or modified
⇄ What changed structurally
  • Array items became repeating <item> elements
  • XML declaration added at the top
  • Curly braces and brackets replaced with tags
  • All values now text content inside tags

How to Convert JSON to XML in 4 Steps

The entire process takes under 30 seconds. The conversion runs in your browser, your data is never sent to any server.

  1. Go to the StackDevTools JSON to XML Converter and paste your JSON data into the input area.
  2. Click Convert to XML. The tool validates your JSON syntax before converting. If there is an error, it is flagged with the line number.
  3. Review the XML output. Check that the structure matches what the receiving system expects, particularly how arrays have been mapped to repeating elements.
  4. Click Copy to copy the XML to your clipboard and paste it wherever you need it.
🔍 Validate your JSON first

Before converting, paste your JSON into the JSON Formatter to validate the syntax and review the structure. A cleaner, well-understood JSON input produces a more predictable XML output. Any syntax errors in the JSON will be flagged before conversion begins, saving you from debugging malformed XML downstream.

Common Issues to Watch For After Conversion

The conversion itself is accurate, but some characteristics of the output may need attention depending on the system receiving the XML:

📐
Array element naming
JSON arrays become repeating elements named after the singular or plural form of the key. Check that the element name matches what the receiving system expects. Some SOAP endpoints are strict about element naming.
🔤
Key names with special characters
JSON keys that start with a number or contain special characters (@, $, spaces) are invalid as XML element names. Rename problem keys in your JSON before converting.
🔢
Numbers and booleans as text
In XML, everything is text. The number 149.99 and the boolean true become text content. Systems that need typed values may require schema validation (XSD) to enforce types on the receiving end.
📄
XML declaration and namespace
Some SOAP endpoints require a specific namespace declaration. If the receiving system returns a namespace error, you may need to add the required xmlns attribute to the root element manually after conversion.

Frequently Asked Questions

Is the conversion lossless? Will any data be lost?

Yes, the conversion is lossless. All data is preserved. The structure looks different, particularly for arrays which become repeating elements, but no values are dropped, modified, or reordered. The XML output contains exactly the same information as the JSON input.

What if my JSON has a syntax error?

The converter validates your JSON syntax before attempting conversion. If there is an error, whether a missing comma, a trailing comma, or an unclosed brace, it is flagged with the line number. The conversion does not proceed until the input is valid JSON.

Does it handle deeply nested JSON?

Yes. The converter handles nested objects and arrays to any depth, preserving the full hierarchy in the XML output. Complex structures with multiple levels of nesting produce correctly nested XML.

Is my data safe when I use this tool?

Yes. All conversion happens directly in your browser using JavaScript. Your JSON data is never sent to any server, never stored, and never accessible to us or any third party. This is particularly important when converting data that contains sensitive information such as customer records or API credentials.

Can I convert large JSON files?

Yes. The tool handles large JSON files. Performance depends on your device's available memory, but most files up to several megabytes convert instantly. For very large files, consider splitting them into smaller batches before converting.

What is the difference between JSON and XML?

JSON uses a compact key-value structure with native support for arrays, booleans, numbers, and null. XML uses a verbose tag-based structure where everything is text and arrays require workarounds. JSON is the standard for modern REST APIs. XML is required by SOAP services, legacy enterprise systems, and regulated industry data standards. See our full JSON vs XML vs YAML comparison guide for a detailed breakdown.

Free browser-based tools

Convert JSON to XML instantly

Validate your JSON, convert to XML or YAML, and compare outputs. All free, all in your browser, no login required.

JSON to XML in Under 30 Seconds

Converting JSON to XML manually is slow, error-prone, and unnecessary. The mapping rules are consistent: objects become elements, arrays become repeating elements, primitives become text content. A converter applies them reliably in under a second.

The practical steps are: validate your JSON first, convert it, review the array mappings, and check for any key name issues before passing the XML to the receiving system. For SOAP integrations specifically, also verify namespace requirements. Those are the one structural detail the converter cannot know about your target endpoint.

All the tools you need are free, run in your browser, and keep your data entirely local. No data leaves your device at any point during the process.