DevBolt
Processed in your browser. Your data never leaves your device.

JSON to XML Conversion Guide

Converting JSON to XML requires mapping JSON's data model (objects, arrays, primitives) to XML's element-based hierarchy. This guide covers the conversion rules, edge cases, and best practices.

← Back to tools

JSON ↔ XML Converter

Convert between JSON and XML formats. Handles nested objects, arrays, attributes, CDATA sections, and XML declarations.

About JSON ↔ XML Conversion

  • JSON (JavaScript Object Notation) — lightweight data format with objects, arrays, strings, numbers, booleans, and null.
  • XML (Extensible Markup Language) — hierarchical markup format with elements, attributes, namespaces, and CDATA sections.
  • JSON → XML: Objects become elements, arrays wrap items in a configurable tag (default: "item"), primitives become text content. Root element name is configurable.
  • XML → JSON: Elements become keys, repeated sibling elements become arrays, attributes use a configurable prefix (default: "@"), text content uses a configurable key (default: "#text").
  • Swap button carries output to input for round-trip conversion.
  • Everything runs in your browser — no data is sent over the network.

How JSON maps to XML elements

JSON objects become XML elements with child elements for each key. JSON arrays require a wrapper element and repeated child elements. Primitives (strings, numbers, booleans) become text content inside their parent element. Null values can be represented with xsi:nil="true" or an empty element.

// JSON input
{
  "user": {
    "name": "Alice",
    "age": 30,
    "active": true,
    "tags": ["admin", "editor"]
  }
}

<!-- XML output -->
<user>
  <name>Alice</name>
  <age>30</age>
  <active>true</active>
  <tags>
    <item>admin</item>
    <item>editor</item>
  </tags>
</user>

Handling arrays in XML

JSON arrays have no direct XML equivalent. The standard approach wraps array items in a parent element matching the JSON key, with each item in a child element (commonly named 'item'). Some converters use the singular form of the parent name — e.g., <books> wrapping <book> elements. DevBolt's converter lets you configure the array item tag name.

When to use JSON vs XML

JSON dominates modern REST APIs, JavaScript/TypeScript ecosystems, and NoSQL databases due to its compact syntax and native JavaScript support. XML remains essential for SOAP web services, enterprise integrations (EDI, HL7), document formats (XHTML, SVG, RSS/Atom), and systems requiring schemas (XSD), namespaces, or mixed content. Many integration workflows require converting between both.

Frequently Asked Questions

Can JSON arrays be represented in XML?

Yes, but XML has no native array type. Arrays are typically represented as a parent element containing repeated child elements with the same tag name. For example, a JSON array [1, 2, 3] becomes <items><item>1</item><item>2</item><item>3</item></items>.

How are JSON null values represented in XML?

Common approaches: an empty self-closing element (<field />), the xsi:nil="true" attribute (<field xsi:nil="true" />), or omitting the element entirely. The best choice depends on your XML schema requirements.

Related Convert Tools