ToolNimba

πŸ” JSON to XML Converter

Shihab Mia By Shihab Mia Β· Updated 2026-08-04

Paste JSON above, then press Convert to XML.

This converter turns JSON into well-formed XML right in your browser. Paste any JSON value (an object, an array, or even a single string or number), choose a root element name and a name for array items, and get clean, indented XML you can copy or download. Objects become nested elements, arrays become repeated elements, and primitive values become text nodes. Special characters are escaped automatically so the result is always valid XML. Nothing is uploaded, the whole conversion happens locally.

What is the JSON to XML?

JSON and XML are both text formats for structured data, and projects often need to move data from one to the other. JSON pairs keys with values and uses square brackets for lists, while XML wraps everything in named tags that can nest inside one another. Because JSON has no built-in tag names for list items, any converter has to make a few sensible choices about how the two shapes line up, and this tool exposes those choices so the output matches what your target system expects.

The mapping used here is the common, predictable one. A JSON object becomes an element whose children are one element per key, named after that key. A JSON array becomes a single element whose children repeat, one per array entry, all sharing the same item element name (item by default, but you can rename it). A primitive (string, number, or boolean) becomes a text node inside its element. A null value, or an empty object or array, becomes a self-closing empty element such as <field />. Everything sits inside one wrapping root element, because XML documents must have exactly one root.

Escaping is what keeps the output valid. The five characters that have special meaning in XML are the ampersand, the less-than sign, the greater-than sign, the double quote, and the apostrophe. The converter replaces each of these with its entity (&amp;, &lt;, &gt;, &quot;, and &apos;) inside every text node, so content like a less than b or AT&T cannot break the markup. Key names are also sanitised, since XML element names cannot contain spaces or start with a digit, so a key like 2024 sales becomes a safe element name such as _2024_sales. The result is XML a parser will accept on the first try.

It is worth knowing what this converter deliberately does not do. Some JSON to XML libraries, such as Python's xmltodict or the so called Badgerfish convention, treat keys that start with an at sign as XML attributes instead of nested elements, so {"@id": "1"} becomes id="1" inside the opening tag rather than a child element. This tool keeps every mapping as a plain nested element, on purpose, because attribute versus element is a modelling decision your target schema should drive, not something a generic converter should guess at. If your XML consumer expects attributes, treat this tool's output as a starting point and move the relevant values into attributes by hand, or restructure the source JSON first.

JSON to XML conversion shows up constantly in real integration work. Legacy enterprise systems, SOAP web services, many banking and government APIs, and older configuration formats still speak XML, while most modern tooling, JavaScript, mobile apps, and REST APIs default to JSON. Rather than hand writing XML or wiring up a full transformation library for a one off task, this converter lets you paste JSON, adjust two names and an indent setting, and get a working XML document in seconds, entirely offline in your browser.

When to use it

  • Feeding data from a JSON API into a legacy system or SOAP service that only accepts XML.
  • Generating an XML config file, RSS-style feed, or sitemap fragment from data you already hold as JSON.
  • Producing sample XML payloads for testing an integration without hand-typing the tags.
  • Learning how a given JSON structure maps onto nested elements and repeated array items.
  • Converting exported JSON reports into XML for tools that only accept XML imports, such as older ERP or CRM systems.
  • Quickly checking what your JSON will look like as XML before writing a formal XSD schema or XSLT transform.

How to use the JSON to XML

  1. Paste or type your JSON into the input box.
  2. Set the root element name (the single tag that wraps the whole document).
  3. Set the array item element name used for each entry inside arrays.
  4. Pick an indent (2 spaces, 4 spaces, tab, or minified) and whether to include the XML declaration.
  5. Press Convert to XML, then copy the result or download it as an .xml file.
  6. If you see an "Invalid JSON" message, fix the reported issue in your input and press Convert to XML again.

Formula & method

Each JSON object becomes one child element per key. Each array becomes repeated item elements, one per entry. Each primitive (string, number, or boolean) becomes a text node. A null value, or an empty object or array, becomes a self-closing empty element. The five XML special characters (ampersand, less-than, greater-than, double quote, and apostrophe) are escaped to their named entities inside every text node so the output is always valid.
How JSON maps to XML{"name":"Ada"}to<name>Ada</name>["a","b"]to<item>a</item><item>b</item>nullto<field />Objects become nested elements, arrays repeat one element per entry,and special characters are escaped so the XML is always well-formed.

Worked examples

Convert the object {"name":"Ada","active":true} with root "user".

  1. The root element <user> wraps everything.
  2. Key "name" becomes <name>Ada</name>.
  3. Key "active" with boolean true becomes <active>true</active>.
  4. Each child is indented one level inside the root.

Result: <user> <name>Ada</name> <active>true</active> </user>

Convert {"tags":["math","logic"]} with root "post" and item name "tag".

  1. The root element <post> wraps everything.
  2. Key "tags" becomes a <tags> element.
  3. Each array entry becomes a <tag> element inside <tags>.
  4. "math" and "logic" become the text nodes of those elements.

Result: <post> <tags> <tag>math</tag> <tag>logic</tag> </tags> </post>

Convert {"note":"a < b & c"} to show escaping, root "data".

  1. Key "note" becomes a <note> element.
  2. The less-than character is escaped to &lt; so it is not read as a tag.
  3. The ampersand is escaped to &amp; so it is not read as an entity start.
  4. The result parses cleanly in any XML reader.

Result: <data> <note>a &lt; b &amp; c</note> </data>

Convert {"products":[{"id":1,"name":"Pen"},{"id":2,"name":"Cup"}]} with root "catalog" and item name "item".

  1. The root element <catalog> wraps everything.
  2. Key "products" becomes a <products> parent element.
  3. Each array entry (an object) becomes an <item> element, since that is the array item name.
  4. Inside each <item>, the "id" and "name" keys become their own nested child elements.

Result: <catalog> <products> <item> <id>1</id> <name>Pen</name> </item> <item> <id>2</id> <name>Cup</name> </item> </products> </catalog>

Convert {"2024 sales":500,"note":"R&D"} with root "report", showing key sanitisation.

  1. The root element <report> wraps everything.
  2. Key "2024 sales" has a space and starts with a digit, so it is sanitised: the space becomes an underscore, then a leading underscore is added because the name cannot start with a digit, giving _2024_sales.
  3. Key "note" becomes a <note> element, with the ampersand in "R&D" escaped to &amp;.

Result: <report> <_2024_sales>500</_2024_sales> <note>R&amp;D</note> </report>

How each JSON type maps to XML in this converter

JSON valueXML output
Object {"k": v}Element <k> per key, nested inside the parent
Array [a, b]Repeated item elements, one per entry
String "hi"Text node: <tag>hi</tag>
Number 42Text node: <tag>42</tag>
Boolean trueText node: <tag>true</tag>
null or empty {} or []Self-closing empty element <tag />

XML special characters and the entities they are escaped to

CharacterNameEscaped as
&Ampersand&amp;
<Less-than&lt;
>Greater-than&gt;
"Double quote&quot;
'Apostrophe&apos;

How different tools represent attributes versus text (for comparison)

ConventionAttribute exampleText content example
This converter (elements only)Not produced, use a separate child element instead<price>9.99</price>
Badgerfish convention{"@id":"1"} becomes id="1" in the tag{"$":"9.99"} becomes the text node
xmltodict (Python library){"@id":"1"} becomes id="1" in the tag{"#text":"9.99"} becomes the text node
Parker conventionAttributes are dropped, only values are keptPlain value with no attribute support

Common mistakes to avoid

  • Expecting JSON keys with spaces or digits to survive unchanged. XML element names cannot contain spaces and cannot start with a digit. A key like "first name" or "2024" is sanitised to a valid name (spaces become underscores, a leading digit gets an underscore prefix), so the tag will not read exactly like the key.
  • Forgetting that XML needs a single root. Unlike JSON, an XML document must have exactly one outermost element. If your JSON is an array or several top-level values, they are all placed inside the one root element you name, rather than sitting side by side.
  • Assuming the conversion is reversible without loss. JSON distinguishes the number 42 from the string "42" and the boolean true from the string "true", but in XML they all become identical text. Converting XML back to JSON cannot recover those types without extra rules.
  • Not escaping special characters yourself. If you build XML by hand you must escape the ampersand, angle brackets, and quotes, or a parser will choke on values like AT&T. This tool escapes them for you, so paste raw text and let the converter handle it.
  • Assuming this tool produces XML attributes. Some JSON to XML libraries turn an at sign prefixed key such as "@id" into an attribute like id="1" inside the opening tag. This converter always creates a nested child element instead, never an attribute, so a key named "@id" simply becomes an element named id after sanitisation.
  • Treating a single item array the same as a plain value downstream. Because every array entry becomes an identically named item element, a one entry array and a multi entry array both look like repeated <item> tags. A downstream system that infers "list" only from seeing more than one element may misread a single entry array as a single value, so check the JSON shape, not just the XML output, when this distinction matters.

Glossary

Element
A named XML tag pair such as <name>Ada</name>, the basic building block of an XML document.
Root element
The single outermost element that wraps the entire XML document. Every valid XML document has exactly one.
Text node
The plain text content sitting between an opening and closing tag, for example the "Ada" in <name>Ada</name>.
Escaping
Replacing characters that have special meaning in XML (ampersand, angle brackets, and quotes) with safe entities so they are read as data, not markup.
Self-closing element
An empty element written as <tag /> with no separate closing tag, used here for null and empty values.
Pretty printing
Adding line breaks and indentation so nested elements are easy to read, as opposed to minified output on one line.
Attribute
A name and value pair inside an opening tag, such as id="1" in <item id="1">. This converter does not create attributes, every JSON key becomes a nested element instead.
Well-formed XML
XML that follows the basic syntax rules: matching tags, exactly one root, and properly escaped characters, so any standard parser can read it without error.

Frequently asked questions

How do I convert JSON to XML?

Paste your JSON into the input box, set a root element name and an array item name, choose your indentation, and press Convert to XML. The tool maps objects to nested elements, arrays to repeated elements, and primitives to text nodes, then escapes special characters so the result is valid XML you can copy or download.

Is my data uploaded anywhere?

No. The conversion runs entirely in your browser using JavaScript. Your JSON never leaves your device and nothing is sent to a server, so it is safe to use with private or sensitive data.

How are JSON arrays turned into XML?

An array becomes a single parent element named after its key, containing one child element per entry. All those children share the same item element name (item by default, which you can change). This is necessary because JSON arrays have no per-item names of their own.

What happens to null values and empty objects?

A null value, an empty object {}, or an empty array [] all become a self-closing empty element such as <field />. This keeps the structure visible in the XML while signalling that there is no content inside.

Are special characters escaped automatically?

Yes. The five XML special characters, the ampersand, less-than, greater-than, double quote, and apostrophe, are replaced with their entities (&amp;, &lt;, &gt;, &quot;, &apos;) inside every text node, so values like a less than b or AT&T cannot break the markup.

Can I convert the XML back into JSON?

You can convert XML back to JSON with an XML to JSON tool, but the round trip is not perfectly lossless. XML stores everything as text, so the distinction between the number 42 and the string "42", or a boolean and its text form, is lost unless extra type rules are applied.

Does this tool convert JSON keys into XML attributes?

No. Every JSON key always becomes a nested child element, never an attribute. Some libraries, such as Python xmltodict, treat an at sign prefixed key like "@id" as an attribute, but this converter keeps the mapping simple and predictable by only producing elements. If you need attributes, add them by hand after converting.

What is the actual difference between JSON and XML?

JSON represents data as typed values, objects, arrays, strings, numbers, booleans, and null, using minimal punctuation. XML represents everything as text wrapped in named tags, with no native concept of a number or boolean, and it additionally supports attributes, namespaces, and comments that JSON has no equivalent for. JSON is generally more compact; XML is generally more self-descriptive and schema-friendly.

Can I convert JSON to XML in Python or another programming language?

Yes, most languages have libraries for this: Python has xmltodict and dicttoxml, JavaScript has packages like js2xmlparser, and Java has the Jackson XML module. This browser tool is aimed at quick, one-off conversions without installing anything; for repeated or large-scale conversions inside an application, a language library is usually the better long-term choice.

Is there a limit to how large or deeply nested my JSON can be?

There is no hard limit built into the tool itself, since conversion happens in your own browser using standard JSON.parse and simple recursion. In practice, extremely large files (many megabytes) or extremely deep nesting can slow down or strain the browser tab, so very large payloads are better handled with a command-line or server-side converter.