JSON to XML Converter

Convert JSON into clean, well-formed XML instantly in your browser.

Looking for XML → JSON?XML to JSON Converter

JSON Input

UTF-8·319 bytes·18 lines
Valid JSON

XML Output

Indentation
XML·280 bytes·10 lines
Valid XML
  • Local Processing
    Your JSON is converted entirely in your browser. Data never leaves your machine.
  • Predictable Mapping
    Objects, arrays, attributes, and text values follow explicit conversion rules.
  • Flexible XML Output
    Configure root elements, attributes, arrays, formatting, and empty values.

Data Modeling

Understanding JSON to XML Mapping

XML requires a single root element, represents properties as elements or attributes, and vectorizes lists. ToolPorta maps JSON data models into clean XML according to deterministic conventions.

Because XML mandates a single enclosing root node, ToolPorta encloses your converted JSON object in a configurable <root> tag. Attributes are mapped with an '@' prefix and text nodes use '#text' for two-way fidelity with XML → JSON.

Sample Conversion Contract

Input JSON Object
{
  "user": {
    "@id": "42",
    "name": "Alice"
  }
}
Generated XML Document
<root>
  <user id="42">
    <name>Alice</name>
  </user>
</root>
JSONXMLExample Mapping
ObjectElement hierarchy{"user": {...}} → <user>...</user>
PropertyChild element{"name": "Alice"} → <name>Alice</name>
@ Prefix PropertyXML Attribute{"@id": "42"} → id="42"
#text PropertyText content{"#text": "Alice"} → <user>Alice</user>
ArrayRepeated <item> elements["A", "B"] → <item>A</item><item>B</item>
nullEmpty element by default{"name": null} → <name/>

Need to convert JSON to XML with attributes, custom root nodes, and array vectorization?

Read the Complete Guide

Best Practices

JSON → XML Edge Cases

Common architectural discrepancies between JSON and XML and how ToolPorta resolves them.

Arrays & Collections

JSON lists cannot exist without a tag name in XML. They are mapped into repeated <item> elements inside their parent property tag.

Null Values

Nulls can be output as empty self-closing elements (<tag/>), omitted from the output tree entirely, or emitted as string 'null'.

Invalid XML Tag Names

Keys containing spaces or starting with numbers can either be sanitized into valid XML identifiers or rejected with a diagnostic error.

Attributes vs Elements

Properties starting with '@' are promoted to XML tag attributes on the enclosing element instead of creating child tags.

Empty Objects & Arrays

Empty maps and empty lists are cleanly collapsed into self-closing XML tags when self-closing is enabled.

Special Characters

Characters like &, <, >, ", and ' are automatically escaped into valid XML entity references (&amp;, &lt;, &gt;, &quot;).

Code Reference

Developer Implementation Guides

Production snippets for serializing JSON data into XML documents across standard runtimes.

// Browser & Node.js via fast-xml-parser
import { XMLBuilder } from "fast-xml-parser";

const jsonData = {
  root: {
    user: {
      "@id": "42",
      name: "Alice"
    }
  }
};

const builder = new XMLBuilder({
  ignoreAttributes: false,
  attributeNamePrefix: "@",
  format: true
});

const xml = builder.build(jsonData);
console.log(xml);

Knowledge Base

Frequently Asked Questions

In XML, elements cannot exist without a tag name. When a JSON array is converted, its parent key becomes the container element, and each element inside the array is assigned the repeated item tag (default <item>). You can customize this tag in Advanced Options.
By prefixing property keys with '@' (for example, "@id": "42"). When combined with a '#text' property for element content, you can easily produce tags like <user id="42">Alice</user>.
The W3C XML standard requires that every document has exactly one root element that encloses all other nodes. Because JSON can have multiple top-level keys or be an array, ToolPorta wraps the converted structure in a configurable <root> element.
By default, null values produce empty self-closing elements like <name/>. Under Advanced Options, you can configure nulls to either be omitted from the output entirely or output as literal text <name>null</name>.
JSON permits spaces and leading digits in keys (such as 'first name' or '123val'), which are illegal XML element names. In default 'Sanitize' mode, spaces are converted to underscores and leading numbers receive an underscore prefix. In 'Show error' mode, an exact error message is shown.
No. All conversion and formatting is executed locally inside your web browser using fast-xml-parser and modern JavaScript APIs. Zero data is sent to external servers.
View all tools (15)