Home/Blogs/Developer Tools Guide

JSON to XML Converter — Complete Guide with Examples, Differences & Free Online Tool (2026)

·12 min read

A practical, no-fluff guide to converting JSON to XML (and XML back to JSON). Learn the real differences between the two formats, when each one is the right choice, how to handle tricky cases like arrays and null values, and how to do it all instantly with a free browser-based converter.

Want to convert right away? Use the free JSON to XML Converter — paste your JSON, get clean XML in one click. Bidirectional: switch to XML → JSON mode anytime. No login, no install, runs entirely in your browser.

A developer I know spent three hours one Friday afternoon trying to get a new e-commerce API to talk to a 15-year-old inventory system at a retail client. The API returned clean JSON. The inventory system spoke nothing but SOAP XML — and was going nowhere fast. That half-day of frustration is probably familiar to anyone who has worked at the boundary between modern web services and legacy enterprise software.

JSON and XML have coexisted for over two decades now, and despite JSON's dominance in modern APIs, XML is very much alive — in healthcare systems (HL7, FHIR), financial reporting (XBRL), configuration files, document formats (DOCX, XLSX under the hood), and thousands of enterprise integrations. Knowing how to convert cleanly between the two, and understanding the gotchas, saves real time.

JSON vs XML — What They Actually Are

Both JSON and XML are text-based formats for representing structured data. That is where the similarity largely ends.

JSON (JavaScript Object Notation) was introduced by Douglas Crockford in the early 2000s as a simpler alternative to XML for browser-server communication. It uses key-value pairs, nested objects (curly braces), and arrays (square brackets). It maps directly to data structures in almost every programming language and is trivially easy to parse.

XML (eXtensible Markup Language) was standardized by the W3C in 1998. It uses a tree of named elements with opening tags, closing tags, and optional attributes. XML supports namespaces, comments, processing instructions, mixed content (text mixed with child elements), and schema validation via XSD (XML Schema Definition).

Feature JSON XML
Syntax styleKey-value pairs, braces, bracketsTag-based, nested elements
VerbosityCompact (~30-50% smaller)More verbose (repeated tags)
Native arraysYes (square bracket syntax)No — use repeated tags
AttributesNoYes (key="value" on tags)
CommentsNoYes (<!-- comment -->)
Schema validationJSON Schema (unofficial)XSD, DTD (W3C standard)
NamespacesNoYes (xmlns)
Data typesString, number, boolean, null, object, arrayAll text (types via XSD)
ReadabilityEasier for developersReadable but noisier
Browser parsingJSON.parse() — trivialDOMParser — more complex

A Side-by-Side Conversion Example

Here is the same data in both formats so you can see the structural difference at a glance.

JSON input:

{
  "catalog": {
    "book": [
      {
        "id": "bk101",
        "author": "Gambardella, Matthew",
        "title": "XML Developer Guide",
        "price": 44.95,
        "inStock": true,
        "notes": null
      },
      {
        "id": "bk102",
        "author": "Ralls, Kim",
        "title": "Midnight Rain",
        "price": 5.95,
        "inStock": false,
        "notes": null
      }
    ]
  }
}

Converted XML output:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book>
    <id>bk101</id>
    <author>Gambardella, Matthew</author>
    <title>XML Developer Guide</title>
    <price>44.95</price>
    <inStock>true</inStock>
    <notes xsi:nil="true" />
  </book>
  <book>
    <id>bk102</id>
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <price>5.95</price>
    <inStock>false</inStock>
    <notes xsi:nil="true" />
  </book>
</catalog>

Notice four things: the JSON array becomes repeated <book> elements; numbers and booleans become text content; null becomes a self-closing tag with xsi:nil="true"; and an XML declaration line is added at the top.

The 5 Conversion Rules You Need to Know

Converting between JSON and XML is not a one-to-one mapping — there are structural mismatches you need to handle deliberately. Here are the five rules that cover 95% of real-world cases.

Rule 1 — Arrays become repeated elements

XML has no array syntax. A JSON array {"items": ["a","b","c"]} is mapped to three sibling <items> elements. When converting XML back to JSON, the converter checks for repeated sibling tags and collapses them into a JSON array automatically.

Rule 2 — Null becomes xsi:nil

The W3C XML Schema standard uses the attribute xsi:nil="true" on a self-closing element to signal a null/absent value. A converter that simply omits null fields silently loses data — make sure yours uses xsi:nil instead.

Rule 3 — Element names must be valid

XML element names cannot start with a digit, cannot contain spaces, and cannot start with the string "xml" (case-insensitive). JSON keys often break these rules — for example "2fa_enabled" or "first name". A robust converter sanitizes these by replacing spaces with underscores and prefixing digit-starting names with an underscore: <_2fa_enabled>.

Rule 4 — Special characters must be escaped

These five characters must be escaped in XML text content:

Character XML Escape Sequence Why It Matters
&&amp;Starts all entity references — must be escaped first
<&lt;Starts a tag — breaks XML parsing if unescaped
>&gt;Ends a tag — technically optional but best practice
"&quot;Required inside attribute values quoted with double-quotes
'&apos;Required inside attribute values quoted with single-quotes

Forgetting to escape ampersands in data like "company": "AT&T" is the single most common source of invalid XML output.

Rule 5 — A single root element is required

Valid XML documents must have exactly one root element wrapping everything. A JSON object at the top level naturally satisfies this — its top-level key becomes the root element. But if your JSON starts with an array (e.g., [{"id":1}, {"id":2}]), the converter needs to wrap it in a synthetic root element like <root> to produce valid XML.

When to Convert JSON to XML (Real Use Cases)

You probably already have a specific use case in mind if you landed on this page. Here are the most common ones, along with what to watch out for in each:

SOAP Web Service Integration

SOAP (Simple Object Access Protocol) is an older web service standard that wraps all requests and responses in XML envelopes. If you are calling a SOAP API from a modern application that generates JSON, you need to convert your payload to XML before sending and parse the XML response back into JSON. This is extremely common in banking, insurance, healthcare, and government integrations.

Enterprise ERP and CRM Systems

SAP, Oracle ERP, and older Salesforce integrations commonly exchange data in XML. If your application collects data as JSON (from a React form, a mobile app, or a modern REST API), you will need to convert to XML before pushing to these systems. The reverse — reading XML responses and converting to JSON for your frontend — is just as common.

Healthcare Data Exchange (HL7, CDA)

Health Level Seven (HL7) and Clinical Document Architecture (CDA) are XML-based standards for exchanging patient records, lab results, and clinical data between hospitals and health systems. FHIR (Fast Healthcare Interoperability Resources) supports both JSON and XML, meaning conversion between the two formats is a routine need for healthcare developers.

RSS and Atom Feeds

If you are building a content aggregator, news reader, or podcast app, you will frequently need to parse RSS (Really Simple Syndication) and Atom feeds — which are XML-based. Converting the feed XML to JSON makes it easier to work with in JavaScript, React, or any modern framework.

Configuration and Build Files

Tools like Maven (pom.xml), Spring Framework, Android manifests, and many CI/CD systems use XML configuration. If you maintain these configurations and want to merge or transform data from a JSON source (say, a deployment config), JSON to XML conversion comes up regularly.

When to Convert XML to JSON

The XML → JSON direction is at least as common as JSON → XML. Here is when you need it:

  • Consuming a SOAP API response — Parse the XML envelope, extract the payload, convert to JSON to work with in your application logic or store in a JSON database.
  • Parsing RSS/Atom feeds — Pull an XML feed, convert to JSON, then render it cleanly in a JavaScript frontend without wrestling with DOMParser.
  • Migrating legacy data — Export XML from an old CMS or database, convert to JSON, and import into a modern system like MongoDB, Firebase, or a REST API backend.
  • Reading configuration exports — Many tools export settings or data as XML. Converting to JSON makes it easier to diff, version control, or programmatically modify.
  • Working with Microsoft Office file formats — DOCX and XLSX are ZIP archives of XML files. Extracting and converting that XML to JSON is sometimes needed for document automation.

How the Free JSON to XML Converter Works

The JSON to XML Converter at ddaverse.com is designed for developers who need accurate results without friction. Here is what it does under the hood:

  • Bidirectional conversion: Switch between JSON → XML and XML → JSON with a single click
  • Proper array handling: JSON arrays are expanded into repeated sibling XML elements; repeated XML siblings are collapsed back into JSON arrays
  • Null handling: JSON null values become xsi:nil="true" self-closing elements — data is never silently dropped
  • XML character escaping: All five special characters (&, <, >, ", ') are escaped correctly so the output is always valid XML
  • Tag name sanitization: Invalid JSON key names are automatically cleaned up to produce valid XML element names
  • Pretty-printed output: Output is indented and formatted for readability — not a collapsed single line
  • Copy and download buttons: Copy the result to clipboard or download as a .xml or .json file
  • Sample data: Load a pre-built example to test the converter instantly
  • Fully offline: Everything runs in your browser using pure JavaScript — no server, no data upload, no tracking

This matters for data privacy. When you are working with customer records, healthcare data, or internal business data, you probably do not want to upload it to a third-party server just to do a format conversion. Because this converter runs entirely in your browser, your data never leaves your machine.

JSON to XML Size Comparison

One of the most commonly asked questions: is XML always bigger than JSON? Almost always yes — but how much depends on the data shape.

Data Structure JSON Size XML Size XML Overhead
Simple flat object (5 fields)~80 bytes~160 bytes+100%
Array of 100 objects (5 fields each)~4.2 KB~7.8 KB+86%
Deeply nested object (4 levels)~1.1 KB~1.8 KB+64%
Long string values~2.0 KB~2.4 KB+20%

Approximate uncompressed sizes. Both formats compress very well with gzip — reducing practical network transfer size by 70-85%.

For APIs serving millions of requests per day, this size difference matters. For one-off data conversions or internal integrations, it rarely does. Both formats compress to similar sizes with gzip/deflate, which is why HTTP/2 APIs compress by default.

Common Mistakes When Converting JSON to XML

  • Silently dropping null values: A converter that skips JSON null fields instead of using xsi:nil="true" can cause downstream systems to fail when they expect a field to be present (even if empty). Always verify null handling.
  • Not validating the output XML: If any JSON key contains characters like &, <, or starts with a digit, naive converters produce malformed XML. Always paste the output into a validator if it will be sent to a production system.
  • Losing type information: XML represents everything as text. If a downstream system needs to know that 44.95 is a number and not a string, you need an XSD schema or type hints — plain XML text cannot express this on its own.
  • Forgetting the XML declaration: While technically optional, <?xml version="1.0" encoding="UTF-8"?> is expected by many parsers and systems. A good converter includes it automatically.
  • Root element issues with JSON arrays: A JSON document that starts with an array (not an object) has no natural root element name. Make sure your converter wraps it sensibly — many use <root> or <items>.
  • Using the wrong tool: Copying JSON data into a generic text editor and manually adding tags is error-prone and slow. Use a dedicated converter that handles escaping, sanitization, and formatting automatically.

Converting JSON to XML in Code

Sometimes you need to convert programmatically in your application rather than using an online tool. Here are the most common approaches:

JavaScript / Node.js

// Using the 'xml' npm package
const xml = require('xml');
const data = { book: [{ title: ['XML Guide'], price: [44.95] }] };
console.log(xml(data));

Python

import json
import dicttoxml

data = json.loads('{"name":"Alice","age":30}')
xml_output = dicttoxml.dicttoxml(data, custom_root='person', attr_type=False)
print(xml_output.decode())

Java

// Using Jackson with jackson-dataformat-xml
ObjectMapper jsonMapper = new ObjectMapper();
XmlMapper xmlMapper = new XmlMapper();

JsonNode node = jsonMapper.readTree(jsonString);
String xmlOutput = xmlMapper.writeValueAsString(node);

For one-off conversions, quick data migrations, or testing payloads before sending to an API, the online tool is faster than writing code. For production pipelines where you need repeatable, automated conversions with custom rules, a library in your application language is the right choice.

How to Use the JSON to XML Converter — Step by Step

  1. Open the tool: Go to ddaverse.com/json-to-xml — no login or install required.
  2. Select direction: Choose "JSON → XML" to convert JSON to XML, or "XML → JSON" to go the other way.
  3. Paste your data: Paste your JSON (or XML) into the left input panel. Or click "Load Sample" to test with example data.
  4. View the result: The converted output appears instantly in the right panel, properly formatted and indented.
  5. Copy or download: Click "Copy" to copy the output to your clipboard, or "Download" to save it as a .xml or .json file.
  6. Use the Reset button: Click the reset icon to clear both panels and start fresh.

Related Developer Tools

  • JSON Formatter — Format, repair, validate, and sort JSON. Supports Format / Fix / Validate / Sort modes.
  • JSON Minifier — Strip whitespace from JSON to reduce file size, with size stats.
  • JSON to CSV Converter — Convert JSON to CSV spreadsheet format (and CSV back to JSON).
  • JSON to YAML Converter — Convert between JSON and YAML — the format used in Docker Compose, Kubernetes, and CI/CD pipelines.
  • JSON Diff — Compare two JSON documents side-by-side and highlight every difference.
  • JSON Tree Viewer — Explore nested JSON as a collapsible, searchable tree structure.

Frequently Asked Questions

What is the difference between JSON and XML?

JSON (JavaScript Object Notation) is a lightweight, text-based data format that uses key-value pairs, arrays, and nested objects. XML (eXtensible Markup Language) is a tag-based markup language that wraps data in opening and closing element tags and supports attributes. JSON is generally more compact and easier to parse in JavaScript; XML is more verbose but supports schemas (XSD), namespaces, comments, and attributes — making it preferred in enterprise and legacy integrations.

How do I convert JSON to XML online for free?

You can use the free JSON to XML Converter at ddaverse.com/json-to-xml. Paste your JSON in the left panel, select 'JSON → XML' direction, and the converted XML appears instantly on the right. No signup, no install, and everything runs in your browser — your data never leaves your machine.

How are JSON arrays converted to XML?

JSON arrays are converted by repeating the parent element tag for each array item. For example, a JSON array like {"book": [{"title": "A"}, {"title": "B"}]} becomes two sibling <book> elements: <book><title>A</title></book><book><title>B</title></book>. XML has no native array concept, so repetition of the same tag is the standard mapping convention.

Can I convert XML back to JSON as well?

Yes. The JSON to XML Converter at ddaverse.com/json-to-xml is bidirectional — switch the direction toggle to 'XML → JSON' and paste your XML to get clean JSON output. The converter handles nested elements, repeated tags (converted to JSON arrays), and text-content nodes automatically.

What happens to JSON null values when converting to XML?

JSON null values are mapped to self-closing XML elements with the xsi:nil="true" attribute — for example, <middleName xsi:nil="true" />. This follows the W3C XML Schema convention for representing absent or null values in XML. When converting back to JSON, xsi:nil="true" elements are typically mapped back to null.

How are JSON boolean and number values represented in XML?

JSON booleans (true/false) and numbers are written as text content inside XML tags — for example, <active>true</active> and <price>44.95</price>. XML does not natively distinguish between strings and numbers in element text; the data type context is typically defined by an XSD schema. When converting XML back to JSON, a smart parser can infer number and boolean types from the text content.

What are the most common reasons to convert JSON to XML?

Common reasons include: integrating with legacy SOAP web services that only accept XML; sending data to enterprise ERP or CRM systems (SAP, Salesforce) that use XML formats; conforming to industry data exchange standards like HL7 (healthcare), XBRL (finance), or RSS/Atom (feeds); and working with XML-based configuration files or document formats.

When should I use XML instead of JSON?

Use XML when: you need to include comments or processing instructions in your data; you require attribute-level metadata on elements; you are working with mixed content (text interspersed with child elements, common in document markup); you need strict schema validation with XSD; or you are integrating with systems that mandate XML — such as SOAP APIs, RSS feeds, Microsoft Office file formats, or SVG.

What special characters need to be escaped in XML?

XML requires five special characters to be escaped in text content: & becomes &amp;, < becomes &lt;, > becomes &gt;, " becomes &quot;, and ' becomes &apos;. A good JSON to XML converter handles all of these automatically. Forgetting to escape ampersands is the most common source of 'not well-formed' XML parse errors.

What is a valid XML element name and why does it matter?

XML element names must start with a letter or underscore (not a digit or hyphen), and can contain letters, digits, hyphens, underscores, and periods. JSON keys that start with a digit or contain spaces (e.g., '2fa-enabled' or 'first name') are not valid XML tag names. A robust converter automatically sanitizes these — for example, prefixing a leading digit with an underscore: <_2fa-enabled>.

Is JSON always smaller than XML?

Usually yes — JSON is typically 30–50% more compact than equivalent XML because it avoids repeated closing tags and angle brackets. For example, {"name":"Alice","age":30} is 24 characters, while <name>Alice</name><age>30</age> is 33 characters before adding a root element. However, for deeply nested or heavily attributed documents, the size difference can vary. Both compress well with gzip, reducing the practical difference in network transfer.

How do I handle XML attributes when converting XML to JSON?

XML attributes (e.g., <book id="bk101">) have no direct JSON equivalent. Common conversion strategies include: promoting attributes to child properties in JSON ({"id":"bk101"}), prefixing attribute keys with @ ({"@id":"bk101"}), or storing them in a nested "_attributes" object. The exact strategy depends on the consuming application. The ddaverse JSON to XML converter uses a clean property-based approach for simplicity.

Sponsored

Sponsored banner