Skip to content
T
Tools.Town
Free Online Tools for Everyone
Data Tools

How to Use JSON to XML — Complete Guide

Learn how to convert JSON to valid XML using the free JSON to XML tool on Tools.Town — configure root elements, attribute mode, and generate well-formed output.

7 May 2026 4 min read By Tools.Town Team Fact Checked

Key Takeaways

  • Each array element becomes a child element
  • Yes
  • The standard XML entities: & → &amp;, < → &lt;, > → &gt;, " → &quot;, ' → &apos;
  • Yes

What is JSON to XML?

JSON to XML converts JSON objects and arrays to well-formed, properly escaped XML, with configurable root element names, optional attributes mode, and standard XML entity escaping.

JSON and XML have different data models — JSON has no analog for XML attributes, comments, or processing instructions. The conversion is a structural approximation, not a lossless round-trip.


Conversion Modes

Child Elements

Default mode — each JSON key becomes a child XML element. Most readable for hierarchical data.

Attributes Mode

Simple string and number values become XML attributes. Produces more compact XML.

Array Handling

Arrays produce repeated child elements. Configure the element tag name for each array.


How to Use JSON to XML

Paste JSON

Paste your JSON object or array. The tool validates syntax before converting.

Set root name

Enter the root element name (e.g. 'root', 'data', 'response').

Configure arrays

Set custom tag names for array items if the default 'item' doesn't fit your schema.

Copy XML

Click Copy to grab the formatted XML output.


Conversion Example

Input JSON:

{ "user": { "name": "Alice", "age": 28, "roles": ["admin", "editor"] } }

Output XML (child elements mode):

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <user>
    <name>Alice</name>
    <age>28</age>
    <roles>
      <item>admin</item>
      <item>editor</item>
    </roles>
  </user>
</root>

Tips & Common Mistakes

XML element names can’t start with numbers. If your JSON keys start with digits (e.g. “1stItem”), the converter prefixes them with an underscore to produce valid XML element names.

Use child elements for complex structures. Attributes mode works well for simple flat objects, but nested objects and arrays always become child elements regardless of mode.


Advertisement

Try JSON to XML Converter — Free

Apply what you just learned with our free tool. No sign-up required.

Try JSON to XML Converter

Frequently Asked Questions

How are JSON arrays converted to XML?
Each array element becomes a child element. The element tag name defaults to 'item' but can be configured. E.g. a 'users' array generates <users><item>...</item></users>.
Can I use attributes instead of child elements?
Yes. Toggle 'Attributes mode' to convert simple string/number values to XML attributes rather than child elements.
What special characters are escaped in the output?
The standard XML entities: & → &amp;, < → &lt;, > → &gt;, " → &quot;, ' → &apos;.
Does it include the XML declaration?
Yes. The output includes <?xml version="1.0" encoding="UTF-8"?> by default. You can toggle this off for embedding in a larger XML document.

Was this guide helpful?

Your feedback helps us improve our content.

Continue Reading

All Data Tools Guides

Get the best Data Tools tips & guides in your inbox

Join 25,000+ users who get our weekly data tools insights.