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.

XML to JSON Converter

Convert XML to JSON online, with attributes, repeated elements and text nodes mapped for you.

Swap directionSwap direction

XML Input

Paste XML, upload an .xml file or drop one here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<!-- Comments and the declaration are dropped -->
<order id="A-1042" status="paid" xmlns:inv="urn:example:inventory">
  <customer>
    <name>Ada Lovelace</name>
    <zip>02134</zip>
    <phone>+4712345678</phone>
  </customer>
  <item sku="K-100" qty="2">Keyboard</item>
  <item sku="M-200" qty="1">Mouse</item>
  <total currency="USD">149.50</total>
  <inv:warehouse>Oslo</inv:warehouse>
  <note><![CDATA[Leave at <front desk> & ring twice]]></note>
  <gift/>
  <express>true</express>
</order>

JSON Output

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

1

Converting…

Convert XML to JSON online

This free XML to JSON converter turns an XML document into formatted JSON while you type. Paste an API response, a SOAP payload, an RSS feed, a pom.xml or an export from an older system, and the JSON appears next to it with the nesting preserved. There is nothing to install and no sign-up, and because the conversion runs in your browser, your XML is never uploaded.

XML and JSON do not map one to one: XML has attributes, mixed text and elements, namespaces and no array type, while JSON has objects, arrays and typed values. The converter follows one predictable set of rules, described below, and lets you adjust the parts that people most often need to change.

How to convert XML to JSON

  1. Paste your XML into the XML Input editor, or click the upload button to open an .xml file. You can also drag a file onto the editor.
  2. The JSON Output updates as you type. If the XML is not well-formed, the status bar shows what is wrong and where, for example the line and column of a mismatched closing tag.
  3. Pick an attribute prefix, decide whether to convert numbers and booleans, and tick always use arrays if your code expects a list for every repeating element.
  4. Click Copy to put the JSON on your clipboard, or Download to save it as data.json.

XML to JSON example

This order has attributes, a repeated item element, a CDATA section, an empty element and a ZIP code with a leading zero. The output below is exactly what the converter produces with its default options.

XML input
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1042" status="paid">
  <customer>
    <name>Ada Lovelace</name>
    <zip>02134</zip>
  </customer>
  <item sku="K-100" qty="2">Keyboard</item>
  <item sku="M-200" qty="1">Mouse</item>
  <note><![CDATA[Leave at <front desk>]]></note>
  <gift/>
</order>
JSON output
{
  "order": {
    "@_id": "A-1042",
    "@_status": "paid",
    "customer": {
      "name": "Ada Lovelace",
      "zip": "02134"
    },
    "item": [
      {
        "@_sku": "K-100",
        "@_qty": 2,
        "#text": "Keyboard"
      },
      {
        "@_sku": "M-200",
        "@_qty": 1,
        "#text": "Mouse"
      }
    ],
    "note": "Leave at <front desk>",
    "gift": ""
  }
}

How XML maps to JSON

XML constructs and the JSON they become
XMLJSON outputNotes
<a>text</a>"a": "text"An element with only text becomes a plain value.
<a id="1"/>"a": { "@_id": 1 }Attributes get the prefix you choose and come first in the object.
<a id="1">text</a>{ "@_id": 1, "#text": "text" }Text next to attributes or child elements moves to #text.
Child elementsNested objectKeys follow the document order of the elements.
Repeated sibling elementsArrayOnly when the name appears more than once under the same parent.
<a/>"a": ""An empty element is an empty string, not null.
CDATA sectionStringTreated as ordinary text, characters like < and & kept.
Comments, processing instructions, declarationDroppedThe <?xml ... ?> line and its encoding are not carried over.
&amp; &#8364;& €Standard entities and numeric character references are decoded.

Attributes

JSON has no attributes, so each one becomes a key on the element's object. A prefix keeps it apart from a child element with the same name. The default @_ is the most common convention for XML to JSON converters, and @, _ or no prefix are also available. With no prefix, an attribute and a child element that share a name would overwrite each other, so the converter stops with an error instead of silently losing one of them.

Repeated elements: sometimes an array, sometimes an object

XML has no array type, so a list is simply an element that repeats. A converter can only see that from the data: one <item> becomes a single value, two become an array. That is why a field can be an object in one response and an array in the next, which breaks code that loops over it. If you consume the JSON from code, tick Always use arrays. Every child element is then wrapped in an array, even when it appears once, so the shape no longer depends on how many items the document happened to contain. The root element and the attributes stay as they are.

Text nodes and mixed content

An element that has text and also attributes or child elements stores its text under #text. Whitespace around text is trimmed, and whitespace-only text between elements is ignored. Mixed content such as <p>one <b>x</b> two</p> is the one case JSON cannot express well: the text pieces are joined into a single #text value (onetwo) and the position of the b element is lost. Documents like HTML or DocBook that rely on mixed content are better kept as XML.

Namespaces

Namespace prefixes are part of the name, so <inv:warehouse> becomes the key inv:warehouse, and a declaration such as xmlns:inv="..." becomes an attribute like any other. The URIs are not resolved, so two elements with the same local name but different prefixes stay separate keys.

Empty elements and null

<gift/> and <gift></gift> both become an empty string, because XML cannot tell an empty value from a missing one. An empty element that has attributes becomes an object holding only those attributes. If your schema expects null, replace the empty strings after converting.

Numbers, booleans and leading zeros

Everything in XML is text. With Convert numbers and booleans on, 42, 12.50, true and false become JSON numbers and booleans, in elements and in attributes. Values where that would change the meaning stay strings: ZIP codes and IDs with a leading zero (02134), phone numbers with a leading plus, hexadecimal and exponent notation, and numbers too large for JavaScript to represent exactly. Note that 12.50 becomes 12.5. If you need the original text, such as prices with fixed decimals, untick the option and every value stays a string.

Why convert XML to JSON?

  • Modern APIs and front ends: JavaScript, mobile and most REST clients work with JSON directly, so converting a legacy XML response saves writing a parser.
  • SOAP and legacy integrations: Inspect a SOAP envelope or an enterprise export as JSON, or feed it to tools that only accept JSON.
  • RSS, Atom and sitemaps: Turn a feed or sitemap.xml into an array of objects you can filter, sort and load into a database.
  • Config and build files: Read Maven, .NET or Android XML files in a script without an XML library.
  • Test data and mocks: Convert an XML fixture into JSON for mock servers and unit tests.

Need to go the other way? The JSON to XML converter builds well-formed XML from JSON, and the YAML to JSON converter and CSV to JSON converter cover two other common sources. Once you have the JSON, the JSON Schema Generator can describe its structure, and the JSON Generator creates sample data for testing.

Frequently Asked Questions

How do I convert XML to JSON?

Paste your XML into the XML Input editor, or upload an .xml file. The JSON appears in the output editor as you type, and a syntax error is reported with its line and column. Copy the result, or click Download to save it as data.json.

How are XML attributes converted to JSON?

Every attribute becomes a key on the element's object, with a prefix so it can be told apart from child elements. The default prefix is @_, so id="7" becomes "@_id": 7. You can switch to @, _ or no prefix in the Attribute prefix menu.

Why is an element sometimes an array and sometimes an object?

XML has no array type, so a list is just an element that repeats. One <item> becomes a single value, and two or more become an array. Tick Always use arrays to get an array for every child element, which keeps the JSON shape the same whatever the data.

Does the converter keep XML comments, CDATA and the declaration?

Comments, processing instructions and the <?xml ...?> declaration are dropped. CDATA sections are kept as ordinary text, with the angle brackets and ampersands inside them preserved.

Will ZIP codes and IDs with leading zeros stay intact?

Yes. A value such as 02134 stays the string "02134" even with Convert numbers and booleans on, as do values starting with + (phone numbers), hex values and numbers too long to represent exactly. Untick the option to keep every value a string.

What happens to XML namespaces?

Prefixed names such as inv:warehouse are kept exactly as written, and xmlns declarations are converted like any other attribute. The converter does not resolve namespace URIs.

Is my XML uploaded to a server?

No. The conversion runs entirely in your browser with JavaScript, so your XML never leaves your device. That makes it safe for feeds, exports and configuration files that contain private data.

Related converters

  • JSON to XML ConverterConvert JSON to well-formed XML with a root element of your choice.
  • 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