PureDevTools

JSON to XML Converter

Convert JSON to XML (and XML to JSON) instantly in your browser — auto-detect, indentation control, root element customization, attribute handling

All processing happens in your browser. No data is sent to any server.

Conversion Direction

Indentation

Attribute Handling

Paste JSON or XML above to convert. Auto-detect picks the direction automatically.

You’re integrating with a legacy SOAP service that requires XML request bodies, but your data source is a modern REST API that returns JSON. The conversion is not a simple string replacement — JSON arrays need wrapping elements, JSON null needs xsi:nil, and nested objects need proper XML element nesting with a configurable root element name.

Why This Converter (Not the JSON to YAML Converter)

PureDevTools has converters for JSON to YAML, CSV, Go, TypeScript, Python, Rust, and SQL. This tool handles JSON↔XML conversion — with root element customization, indentation control, and attribute handling for XML conventions. Everything runs in your browser; no data is sent anywhere.

What Is JSON to XML Conversion?

JSON (JavaScript Object Notation) and XML (eXtensible Markup Language) are two of the most widely used data interchange formats. While JSON is the default choice for modern REST APIs and JavaScript applications, XML remains essential in enterprise integrations, SOAP web services, document formats (SVG, DOCX, RSS), and configuration files (Maven, Spring, Android manifests).

This converter translates between both formats directly in your browser — no server, no tracking, no data sent anywhere.

JSON vs. XML — Format Comparison

FeatureJSONXML
Syntax{ } objects, [ ] arrays, quoted keys<element> tags, attributes, text content
Data typesstring, number, boolean, null, array, objecttext only (all values are strings)
ArraysNative [ ] supportRepeated sibling elements
AttributesNot supportedYes — <tag attr="val">
CommentsNot supported<!-- comment -->
File sizeTypically smallerLarger due to closing tags
Human readabilityHighHigh (but more verbose)
NamespacesNot supportedYes
Schema validationJSON SchemaXSD, DTD, RELAX NG

JSON to XML Conversion Rules

Objects → Elements

JSON objects become XML parent elements. Each key becomes a child element:

{
  "server": {
    "host": "localhost",
    "port": 8080,
    "tls": true
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <server>
    <host>localhost</host>
    <port>8080</port>
    <tls>true</tls>
  </server>
</root>

Arrays → Repeated Elements

JSON arrays are represented by repeating the same element tag for each item — XML has no native array type:

{
  "colors": ["red", "green", "blue"]
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <colors>red</colors>
  <colors>green</colors>
  <colors>blue</colors>
</root>

Null Values → xsi:nil

JSON null is represented using the xsi:nil="true" attribute convention from XML Schema:

{ "deleted": null }
<deleted xsi:nil="true"/>

Primitives → Text Content

Strings, numbers, and booleans become the text content of their element:

{ "count": 42, "active": true, "label": "hello" }
<root>
  <count>42</count>
  <active>true</active>
  <label>hello</label>
</root>

Root Element Name

XML requires exactly one root element. When your JSON is a plain object or array, this converter wraps it in a configurable root element (default: root). You can set any valid XML name — for example, response, data, config, or your resource type.

Valid XML element names start with a letter or underscore, followed by letters, digits, hyphens, underscores, or periods. Invalid characters are automatically replaced with underscores.

Attribute Handling Modes

XML supports both child elements and attributes on the same tag. Three modes control how this converter maps JSON keys to XML:

None (Default)

All JSON keys become child elements. This is the safest, most compatible mode — no assumptions are made about which keys should be attributes:

{ "id": "u1", "name": "Alice" }
<root>
  <id>u1</id>
  <name>Alice</name>
</root>

@ Prefix

JSON keys starting with @ become XML attributes; other keys become child elements. This convention is used by popular libraries such as xml2js, xmlbuilder2, and Badgerfish:

{ "@id": "u1", "@type": "user", "name": "Alice" }
<root id="u1" type="user">
  <name>Alice</name>
</root>

Wrapper

Scalar values (strings, numbers, booleans) are stored in a value= XML attribute rather than as element text content. This is useful for certain legacy systems or when distinguishing elements from their values:

{ "timeout": 30, "retries": 3 }
<root>
  <timeout value="30"/>
  <retries value="3"/>
</root>

XML to JSON Conversion

Paste XML into the input box and the converter will parse it and output JSON. The converter handles:

Array Detection from XML

When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array:

<users>
  <user>Alice</user>
  <user>Bob</user>
  <user>Carol</user>
</users>
{
  "user": ["Alice", "Bob", "Carol"]
}

Indentation Control

Choose 2 or 4 spaces for the output indentation:

Both options produce equivalent XML/JSON; the choice is purely cosmetic.

Common Use Cases

Converting REST API Response to XML

When integrating a modern REST API with a legacy system that requires XML:

{
  "order": {
    "id": "ORD-123",
    "customer": "Alice",
    "total": 99.99,
    "items": ["Widget A", "Widget B"]
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <order>
    <id>ORD-123</id>
    <customer>Alice</customer>
    <total>99.99</total>
    <items>Widget A</items>
    <items>Widget B</items>
  </order>
</root>

Parsing XML Configuration to JSON

Many build tools and enterprise systems (Maven, Spring, Android) use XML configuration. Converting to JSON makes the data easier to manipulate programmatically:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <database>
    <host>localhost</host>
    <port>5432</port>
    <name>mydb</name>
  </database>
  <cache>
    <ttl>3600</ttl>
    <maxSize>1000</maxSize>
  </cache>
</config>
{
  "database": {
    "host": "localhost",
    "port": 5432,
    "name": "mydb"
  },
  "cache": {
    "ttl": 3600,
    "maxSize": 1000
  }
}

RSS / Atom Feed Parsing

RSS and Atom feeds are XML-based. Converting to JSON simplifies processing in JavaScript:

<item>
  <title>New Release</title>
  <link>https://example.com/release</link>
  <pubDate>Mon, 25 Feb 2026 00:00:00 GMT</pubDate>
</item>
{
  "title": "New Release",
  "link": "https://example.com/release",
  "pubDate": "Mon, 25 Feb 2026 00:00:00 GMT"
}

Frequently Asked Questions

Is the conversion lossless? JSON → XML is generally lossless for data values. However, XML has no native array type — arrays become repeated sibling elements, which is a structural difference. XML → JSON may lose XML comments, processing instructions, and namespace declarations, which have no JSON equivalent.

What happens with invalid JSON keys for XML? XML element names must start with a letter or underscore and contain only letters, digits, hyphens, underscores, and periods. If a JSON key contains spaces or special characters (e.g., "my key!", "123start"), this converter automatically sanitises it to a valid XML name (e.g., my_key_, _123start).

Can I convert XML with namespaces? Basic namespace prefixes in element names are preserved as-is in the output. Full namespace resolution (expanding xmlns: declarations) is not currently performed.

Why does XML use repeated tags for arrays instead of a special syntax? XML was designed as a document markup language, not a data serialisation format. There is no standard way to distinguish a single element from an array of one element — tools that parse XML to JSON must infer array status from sibling counts (which this converter does automatically).

What is xsi:nil? xsi:nil="true" is an attribute from the XML Schema Instance namespace that marks an element as explicitly null. This converter uses it to represent JSON null values in XML output, and recognises it when parsing XML back to JSON.

Does this tool send my data to a server? No. All conversion happens in your browser using JavaScript. Nothing is uploaded or transmitted.

Related Tools

More JSON Tools