JSONGenerator
GeneratorSchemaConvertersExamplesDocs

JSONGenerator

Free online tools for generating random JSON data and JSON Schemas.

Quick Links

  • JSON Generator
  • JSON Schema Converter
  • Examples
  • Docs
  • Blog
  • About
  • Contact
  • Privacy Policy

Converters

  • JSON to YAML
  • YAML to JSON
  • XML to JSON
  • JSON to XML
  • JSON to TOML
  • TOML to JSON
  • JSON to CSV
  • CSV to JSON
  • JSON to Excel
  • Excel to JSON
  • JSON to HTML table
  • JSON to TypeScript
  • JSON to C#
  • JSON to Go
  • JSON to Java
  • JSON to SQL

Support

Having issues? Contact us.

© 2026 JSON Generator. All rights reserved.

JSON to XML Converter

Paste JSON and get well-formed, indented XML as you type.

Swap directionSwap direction

JSON Input

Paste JSON, upload a .json file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
  "order": {
    "@_id": "A-1042",
    "customer": "Ada & Sons <ada@example.com>",
    "paid": true,
    "discount": null,
    "items": [
      { "sku": "X-100", "qty": 2, "price": 19.95 },
      { "sku": "X-200", "qty": 1, "price": 5 }
    ],
    "shipping address": {
      "city": "Oslo",
      "2nd line": "Apt 4"
    },
    "note": {
      "@_lang": "en",
      "#text": "Leave at the door"
    }
  }
}

XML Output

Updates as you type. Copy it or download a .xml file.

1

Converting…

Convert JSON to XML online

This free JSON to XML converter turns a JSON document into well-formed, indented XML. Paste an API response, a config file or an export from a database, and the XML version appears right away, with your key order and nesting intact. There is nothing to install and no sign-up, and because the conversion runs in your browser, your data is never uploaded.

JSON and XML model data differently. JSON has objects, arrays and typed values; XML has elements, attributes and text, and requires a single root element. The converter bridges the two with a small set of predictable rules, described below, so you can feed the result to a SOAP service, an RSS or sitemap tool, an enterprise integration or any other system that still expects XML.

How to convert JSON to XML

  1. Paste your JSON into the JSON Input editor, or click the upload button to open a .json file. You can also drag a file onto the editor.
  2. The XML Output updates as you type. If the JSON is invalid, the status bar shows the parser's error so you can fix it.
  3. Optionally type a different Root element name, or untick XML declaration if you do not want the <?xml ... ?> line.
  4. Click Copy to put the XML on your clipboard, or Download to save it as data.xml.

JSON to XML example

Objects become nested elements, the array becomes two <tags> elements, the @_id key becomes an attribute, and the ampersand in the title is escaped. The null value turns into an empty <stock/> element.

JSON input
{
  "book": {
    "@_id": "b1",
    "title": "Dune & Co",
    "tags": ["sci-fi", "classic"],
    "price": 9.99,
    "stock": null
  }
}
XML output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <book id="b1">
    <title>Dune &amp; Co</title>
    <tags>sci-fi</tags>
    <tags>classic</tags>
    <price>9.99</price>
    <stock/>
  </book>
</root>

How JSON maps to XML

JSON structures and their XML equivalents
JSONXML outputNotes
{ } objectNested child elementsAn empty object is written <name/>.
[ ] arrayRepeated elements named after the keyTop-level and nested arrays use <item>; an empty array writes nothing.
stringEscaped text contentWhitespace and line breaks are kept as they are.
number, booleanText contentWritten as JSON would write them: 9.99, true, 1e+21.
null<name/>An empty element, the same as an empty string.
@_namename="..."An attribute on the parent element.
#textText content of the parent elementUse it together with attributes or child elements.

The root element and top-level arrays

A JSON document can be an object, an array or a single value, but XML always needs exactly one root element. The converter wraps whatever you paste in <root>; set the Root element option to use a more meaningful name such as catalog or response. A top-level array becomes a list of <item> children under that root, and a bare value such as 42 becomes <root>42</root>.

Arrays and repeated elements

XML has no array type, so a list is written as the same element repeated. With "user": [{ "id": 1 }, { "id": 2 }] you get two <user> elements. Arrays inside arrays have no key to name them, so each inner list becomes an element holding <item> children. Because empty arrays write no elements at all and a one-item array looks like a single element, converting the XML back to JSON does not always restore the original array shape.

Attributes and text content

Keys that start with @_ are written as attributes of the element they belong to, and the key #text holds its text. So { "note": { "@_lang": "en", "#text": "Hi" } } becomes <note lang="en">Hi</note>. These are the same names the XML to JSON converter produces, so JSON that came from XML converts back to the same elements and attributes. When an element has both text and child elements, the text is written first and the converter does not re-indent it, because whitespace in mixed content can be significant.

Keys that are not valid XML names

JSON keys can be any string, but XML element and attribute names cannot contain spaces or most symbols and cannot start with a digit. The converter replaces every character other than letters, digits, _, -, . and : with an underscore, and adds a leading underscore when the name does not start with a letter or underscore. An empty key becomes _. If two keys end up with the same name, both are kept as repeated elements.

Examples of how JSON keys become XML names
JSON keyXML name
first namefirst_name
2nd_2nd
price ($)price____
soap:Bodysoap:Body

Escaping and invalid characters

The characters &, <, >, double quotes and apostrophes are escaped in both text and attribute values, so the output stays well-formed no matter what your strings contain. Control characters that XML 1.0 forbids, such as \u0000, are removed. Colons are kept in names so prefixed names such as soap:Body pass through, but the converter does not add namespace declarations; include them yourself as @_xmlns:soap attributes if your consumer needs them.

Why convert JSON to XML?

  • SOAP and legacy integrations: Many banking, insurance and ERP systems accept only XML, even when your own services speak JSON.
  • Feeds and sitemaps: RSS, Atom and product feeds are XML; build the data as JSON, convert it, then adjust the element names.
  • Config and build files: Tools such as Maven, Android and .NET read XML, and generating it from JSON is quicker than writing it by hand.
  • Test data: Turn a sample payload into an XML fixture for a parser or an XSLT transformation you are testing.

To go the other way, use the XML to JSON converter. If you prefer a more human-friendly config format, try the JSON to YAML converter, or flatten an array of records with the JSON to CSV converter. Need sample JSON to experiment with? Create some with the JSON Generator, validate its structure with the JSON Schema Generator, or read how other serialization formats compare in Protobuf vs JSON.

Frequently Asked Questions

How do I convert JSON to XML?

Paste your JSON into the JSON Input editor, or upload a .json file. The XML appears in the output editor as you type, wrapped in a root element. Copy it, or click Download to save it as data.xml.

Why does the XML have a root element?

An XML document must have exactly one top-level element, while JSON can start with an object, an array or a plain value. The converter wraps your data in a root element named root by default. Type another name in the Root element field to change it.

How are JSON arrays converted to XML?

An array under a key becomes repeated elements with that key's name, so "tags": ["a", "b"] gives two <tags> elements. A top-level array, or an array inside an array, uses <item> elements. Empty arrays produce no elements.

How do I create XML attributes from JSON?

Start the key with @_ and the converter writes it as an attribute, so "@_id": "7" becomes id="7" on the parent element. Use the key #text for the element's text content. This is the same convention the XML to JSON converter produces.

What happens to JSON keys that are not valid XML names?

Characters that XML names cannot contain, such as spaces and symbols, are replaced with an underscore, and a name that starts with a digit gets a leading underscore. For example, "first name" becomes <first_name> and "2nd" becomes <_2nd>.

How is null written in XML?

A null value becomes an empty, self-closing element such as <discount/>. XML has no null type, so an empty string and an empty object are written the same way.

Is my JSON uploaded to a server?

No. The conversion runs entirely in your browser with JavaScript, so your data never leaves your device.

Related converters

  • XML to JSON ConverterConvert XML to JSON with attributes, repeated elements and text nodes mapped predictably.
  • JSON to YAML ConverterConvert JSON to clean, readable YAML for config files, Kubernetes and CI pipelines.
  • YAML to JSON ConverterConvert YAML, including anchors and multi-document files, to formatted JSON.
  • JSON to TOML ConverterConvert JSON to TOML for Cargo, pyproject and other config files.
  • TOML to JSON ConverterConvert TOML tables, arrays of tables and dates to JSON.
  • JSON to CSV ConverterConvert a JSON array to CSV, with nested objects flattened into columns.

See all JSON converters