ToolNimba Browse

🔁 JSON to XML Converter

By ToolNimba Developer Tools Team · Updated 2026-06-19

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 ways to represent structured data as text, 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 < 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 results becomes a safe element name. The result is XML a parser will accept on the first try.

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, 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.

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.

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.

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 < character is escaped to &lt; so it is not read as a tag.
  3. The & character 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>

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;

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 a 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 & < > 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.

Glossary

Element
A named XML tag pair such as <name>…</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 (& < > " ') 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.

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 < 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.