JSON to XML Converter Online Free – Convert JSON Data to XML

⚙️ Developer Tools Free Forever

JSON to XML Converter – Convert JSON Data to XML Free Online

Convert any JSON object or array to properly nested, formatted XML. Customize root tags, array item names, indentation, and attribute prefixes. Download the result as a .xml file.

Examples:
Root element
Array item tag
Indent spaces
JSON Input
XML Output
About This Tool

Turning JSON into well-formed XML, with real tag name sanitization and attribute support

JSON and XML disagree about almost everything: JSON has no concept of attributes, no required root element, and object keys that can contain characters no XML tag name is allowed to have. This converter is a recursive function that resolves each of those mismatches with an explicit rule, rather than just wrapping keys in angle brackets and hoping the result parses.

The conversion is entirely local. The script makes no network requests, so the JSON you paste and the XML it produces stay inside the browser tab.

The recursive converter, by value type

Step 1 Sanitize the tag name Every key runs through a toTag function before use. Characters outside a-z A-Z 0-9 . _ - are replaced with an underscore, and if the result starts with a digit or a disallowed character, an underscore is prepended, since XML names must begin with a letter or underscore.
Step 2 Null becomes xsi:nil A JSON null value does not disappear silently. It renders as a self-closing tag carrying xsi:nil="true", the XML Schema convention for explicitly representing a null, rather than an empty element that could be mistaken for an empty string.
Step 3 Arrays repeat the tag A JSON array has no native XML equivalent, so each array element is rendered as a separate element using the same tag name, repeated one after another at the same indent level. This is the same convention most JSON-to-XML libraries use.
Step 4 Objects recurse, keys starting with @ become attributes With the attribute option on, any key beginning with @ is pulled out of the child list and written as an XML attribute on the parent element instead of a nested child element. A key named #text or _ as the sole remaining child is treated as the element’s text content.
// simplified from the actual converter if (value === null) { return pad + ‘<‘ + tagName + ‘ xsi:nil=”true”/>’; } if (Array.isArray(value)) { return value.map(function(item) { return jsonToXml(item, tagName, pad, indentStr, useAttrPrefix); }).join(‘\n’); } if (useAttrPrefix && key.startsWith(‘@’)) { attrs += ‘ ‘ + toTag(key.slice(1)) + ‘=”‘ + escapeXml(value[key]) + ‘”‘; }

Escaping and the five reserved characters

Text content and attribute values both run through an escape function that replaces the five characters XML reserves for markup: ampersand becomes &amp;, less than becomes &lt;, greater than becomes &gt;, double quote becomes &quot;, and apostrophe becomes &apos;. That is the complete predefined entity set from the XML 1.0 specification, and it is applied uniformly whether the value ends up as element text or an attribute value.

OptionEffect on output
Root element nameWraps the entire document, defaults to root if left blank
Item element nameUsed for each element when the top-level JSON value is an array, defaults to item
Indent sizeNumber of spaces per nesting level, built by repeating a space string
XML declarationPrepends <?xml version="1.0" encoding="UTF-8"?> when checked
Attributes from @keysReinterprets any key starting with @ as an XML attribute rather than a child element
Top-level arrays get an extra wrapping layer. If your JSON root is an array rather than an object, there is no key to name the repeated element after, so the tool wraps the whole array in the root element and names each item using the separate item tag setting. A plain array of three numbers therefore becomes a root element containing three item elements, not three bare top-level elements, since XML requires exactly one root element for the document to be well-formed.

Two conventions this tool follows

Empty object or array

Renders as a self-closing tag, <tag/>, rather than an open and close tag pair with nothing between them. Both are valid XML and parse identically, but the self-closing form is the more compact convention.

xsi:nil without a namespace declaration

The tool writes the xsi:nil attribute directly without also emitting the corresponding xmlns:xsi namespace declaration on the root. Strict XML Schema validators expect that namespace to be declared, so add it manually if you are validating against a schema rather than just reading the XML.

Tag name sanitization Attribute prefix convention xsi:nil for null values Single-root wrapping for arrays

XML and JSON standards

Where the two formats collide

Producing XML payloads for a legacy SOAP endpoint that will not accept JSON, converting a JSON config into an XML format an older enterprise system expects, generating sample XML fixtures for testing an XML parser, and preparing feed data for an RSS or Atom style consumer that requires a specific element and attribute layout.

Common Questions

Questions About the JSON to XML Converter

JSON arrays are converted to repeated sibling XML elements. By default each item gets the tag name “item”, but you can set any name in the Array item tag field. For example, a JSON array of user objects with Array item tag set to “user” will generate multiple <user></user> elements inside the root element. If the root JSON is an array, all items are wrapped inside the root element you specify.

When enabled, any JSON key starting with @ is converted to an XML attribute on its parent element rather than a child element. For example, {“@id”:”123″,”name”:”Alice”} becomes <item id=”123″><name>Alice</name></item>. This lets you pre annotate your JSON to control which values become attributes in the XML output.

This tool converts JSON to XML only. For XML to JSON conversion, look for a dedicated XML to JSON converter tool. Reversing the conversion is non trivial because XML has concepts (attributes, namespaces, processing instructions, mixed content) that have no direct JSON equivalent, so different tools may produce different JSON structures from the same XML.

Yes. All five XML special characters are escaped: & becomes &amp;, < becomes &lt;, > becomes &gt;, double quotes become &quot;, and apostrophes become &apos;. The output is well formed XML and will pass any XML parser without issues.

JSON null values are represented as self closing elements with the xsi:nil=”true” attribute, following the XML Schema standard convention for absent or null values. For example, {“middleName”:null} becomes <middleName xsi:nil=”true”/>.

The converter sanitizes JSON keys to produce valid XML tag names. Spaces and invalid characters are replaced with underscores. Keys starting with a digit or special character get a leading underscore. For example a key “123 foo bar” becomes “_123_foo_bar” as an XML element name. This ensures the output is always well formed XML even with unconventional JSON key names.

There is no hard limit imposed by the tool, but very large JSON documents (several MB or more) may be slow to convert because the processing runs in your browser’s JavaScript engine. For production use with large datasets, use a server side library like xml2js (Node.js), lxml (Python), or JAXB (Java) which are optimized for throughput.

No. The entire conversion runs in your browser using JavaScript. Your JSON data never leaves your machine. This makes the tool safe to use with internal APIs, sensitive configuration data, and any JSON that contains credentials or personal information.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.