WebToolsPlanet
Converter Tools

XML Generator

Generate XML from JSON data. Paste any JSON object or array and convert it to well-formed XML with configurable root element, indent, attribute prefix, and XML declaration.

Last updated: May 28, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is XML Generator?

An XML generator that converts JSON data to well-formed XML. This is the reverse of an XML-to-JSON converter — useful when you need to produce XML output from JSON data, integrate with SOAP or XML-based systems from modern JSON APIs, or build XML configuration and data files programmatically.

The tool intelligently handles JSON objects, arrays, and primitive values. Arrays are serialised as repeated same-name XML elements. Keys starting with @ are treated as XML attributes. The special key #text sets the text content of an element when attributes and children co-exist. This convention matches popular libraries like xml2js, fast-xml-parser, and xmlbuilder2.

How to Use XML Generator

1

Paste your JSON into the input area on the left

2

The XML output appears instantly on the right

3

Set the "Root Element" name to control the wrapper element (used when JSON has multiple top-level keys or is an array)

4

Use @ prefix in your JSON keys to create XML attributes (e.g., "@id": "1" → id="1")

5

Toggle "XML Declaration" to add or remove the <?xml ...?> header line

6

Click "Copy XML" or "Download .xml" to save the output

Common Use Cases

  • Generating SOAP request bodies from JSON data
  • Converting REST API JSON responses to XML for legacy system integration
  • Creating XML configuration files from JSON settings
  • Building XML data feeds from JSON objects
  • Testing XML parsing tools by generating known XML from controlled JSON
  • Generating Maven POM-like XML structures from JSON dependency lists

Example Input and Output

A JSON object with attributes and nested elements converted to XML:

JSON input
{
  "person": {
    "@id": "42",
    "@active": "true",
    "name": "Alice Johnson",
    "email": "alice@example.com",
    "address": {
      "street": "123 Main St",
      "city": "Boston",
      "zip": "02101"
    },
    "tags": ["developer", "designer"]
  }
}
XML output
<?xml version="1.0" encoding="UTF-8"?>
<person id="42" active="true">
  <name>Alice Johnson</name>
  <email>alice@example.com</email>
  <address>
    <street>123 Main St</street>
    <city>Boston</city>
    <zip>02101</zip>
  </address>
  <tags>developer</tags>
  <tags>designer</tags>
</person>

How This Tool Works

The JSON input is parsed with JSON.parse. A recursive serialiser walks the resulting JavaScript object tree. Object keys starting with the attribute prefix (@ by default) are emitted as XML attributes on the enclosing element. The special #text key sets mixed text content. Arrays produce repeated sibling elements with the parent key as the tag name. All values are XML-escaped (& → &amp;, < → &lt;, etc.). The output is assembled as a plain string.

Technical Stack

JSON.parseCustom recursive XML serialiserXML character escapingClient-side only

Privacy First

JSON to XML conversion runs entirely in your browser. Your JSON data is never transmitted to our servers.

Attribute Prefix Convention

The @ prefix for attributes matches the xml2js and fast-xml-parser convention used in Node.js ecosystems. If you are using a different convention (e.g., _ or -attr), you can change the attribute prefix in the options panel.

Frequently Asked Questions

How do I create XML attributes from JSON?
Prefix the JSON key with @ and it will be serialised as an XML attribute on the parent element. For example, {"person": {"@id": "1", "name": "Alice"}} produces <person id="1"><name>Alice</name></person>. The attribute prefix can be changed in the options if you prefer a different convention.
How are JSON arrays converted to XML?
JSON arrays are serialised as repeated XML elements with the same tag name. For example, {"tags": ["a", "b"]} produces <tags>a</tags><tags>b</tags>. If the array is under the root level, these elements are siblings under the parent. This is the inverse of how XML-to-JSON tools handle repeated elements.
What happens when a JSON key is not a valid XML element name?
XML element names must start with a letter or underscore and contain only letters, digits, hyphens, underscores, periods, and colons. If a JSON key contains invalid characters (spaces, $, #, numbers at the start), the tool sanitises it by replacing invalid characters with underscores and prepending _ if the first character is invalid.
What does the root element setting do?
When your JSON has multiple top-level keys or is an array, the tool wraps the output in a configurable root element. If your JSON is already a single-key object (like {"person": {...}}), the tool uses that key as the root and the "Root Element" setting is ignored.
Is there a size limit for JSON input?
There is no hard limit enforced by the tool — it runs entirely in your browser. Very large JSON documents (several MB) will generate proportionally large XML and may take a moment to process, depending on your device. For routine development use (API responses, config files, test data), performance is instant.