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.
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
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.
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.
@ 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.
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 &, less than becomes <, greater than becomes >, double quote becomes ", and apostrophe becomes '. 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.
| Option | Effect on output |
|---|---|
| Root element name | Wraps the entire document, defaults to root if left blank |
| Item element name | Used for each element when the top-level JSON value is an array, defaults to item |
| Indent size | Number of spaces per nesting level, built by repeating a space string |
| XML declaration | Prepends <?xml version="1.0" encoding="UTF-8"?> when checked |
| Attributes from @keys | Reinterprets any key starting with @ as an XML attribute rather than a child element |
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.
XML and JSON standards
- W3C XML 1.0 specification defines the naming rules and the five predefined character entities this converter relies on.
- W3C XML Schema, xsi:nil documents the convention this tool uses to represent JSON null values.
- Json.NET, converting between JSON and XML is a widely referenced implementation of the same @attribute and #text conventions this tool follows.
- MDN, DOMParser is useful if you want to validate the resulting XML string is well-formed by parsing it back in the browser.
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.
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 &, < becomes <, > becomes >, double quotes become ", and apostrophes become '. 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.
From the blog
Deep dives on the things these tools touch
Minification, UUID collisions, diffing API responses, and the other questions that come up around this toolset.