How to Convert JSON to XML Online

Most modern APIs speak JSON. But enterprise systems — ERP platforms, payment processors, legacy integrations — often still speak XML. If you find yourself needing to bridge that gap, understanding how the two formats map to each other makes the conversion predictable rather than a guessing game.

JSON and XML side by side

Both formats represent hierarchical data. The difference is in how they express structure:

Feature JSON XML
Structure Keys and values in {} objects Opening and closing element tags
Arrays [] with comma-separated values Repeated elements with the same tag name
Comments Not supported Supported with <!-- -->
Attributes No equivalent Inline on opening tags
Schema validation JSON Schema XSD (XML Schema Definition)
Verbosity Compact More verbose (opening + closing tags)

How the conversion works

There is no single official standard for mapping JSON to XML, but there is a widely used convention that most converters follow:

Example: object to XML

Input JSON:

{
  "name": "John Smith",
  "age": 30,
  "active": true,
  "email": "john@example.com"
}

Output XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name>John Smith</name>
  <age>30</age>
  <active>true</active>
  <email>john@example.com</email>
</root>

Example: nested object with array

Input JSON:

{
  "user": {
    "name": "Jane",
    "roles": ["admin", "editor"],
    "address": {
      "city": "London",
      "country": "UK"
    }
  }
}

Output XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <user>
    <name>Jane</name>
    <roles>admin</roles>
    <roles>editor</roles>
    <address>
      <city>London</city>
      <country>UK</country>
    </address>
  </user>
</root>

Notice that the roles array becomes two <roles> elements — one per array item. This is the most common convention for arrays in XML.

Example: top-level array

When the JSON root is an array, each item becomes an <item> child inside <root>:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <item>
    <id>1</id>
    <name>Alice</name>
  </item>
  <item>
    <id>2</id>
    <name>Bob</name>
  </item>
</root>

What to watch out for

Special characters in values

XML has five reserved characters that must be escaped inside element content:

CharacterXML Escape
&&amp;
<&lt;
>&gt;
"&quot;
'&apos;

A proper converter handles this automatically. If a JSON string value contains < or &, those characters will be escaped in the XML output so the document remains valid.

Invalid XML element names

XML element names cannot start with a number, cannot contain spaces, and cannot use most special characters. JSON keys like "1stName", "first name", or "user@id" are valid JSON but would produce invalid XML tags. A safe converter replaces invalid characters with underscores and prefixes numeric starts with an underscore: _1stName, first_name, user_id.

Null values

JSON's null becomes an empty XML element: <field></field>. There is no XML equivalent of null — it is represented by an empty element or by omitting the element entirely, depending on your schema.

When to convert JSON to XML

Convert JSON to XML instantly

Paste any JSON object or array and get properly formatted, escaped XML output. Handles nested objects, arrays, and special characters automatically. Free, private, no signup required.

Open JSON to XML Converter

Frequently Asked Questions

Can all JSON be converted to XML?

Yes, any valid JSON document can be represented as XML. The main challenge is that XML element names have stricter naming rules than JSON keys — invalid characters get replaced with underscores by a proper converter.

What happens to JSON arrays when converted to XML?

Arrays become repeated elements with the same tag name. A skills array with three values becomes three separate <skills> elements. Top-level arrays use <item> inside a <root> wrapper.

When should I convert JSON to XML?

When integrating with legacy enterprise systems, SOAP web services, RSS feeds, or any other system that requires XML as its input format. JSON is standard for REST APIs; XML remains standard for many older protocols and document formats.