🛠️ Developer & Web

XML to JSON Converter

Turn XML documents and API responses into JSON.

  • 3attribute prefix choices
  • #textfor mixed content
  • Autoarrays for repeats
  • BrowserXML parser

How to use the XML to JSON

  1. 1

    Paste XML

    An API response, an RSS feed, a config file or an export from accounting or e-commerce software.

  2. 2

    Pick an attribute prefix

    @name (default), _name, or none at all.

  3. 3

    Set the two switches

    Parse numbers & booleans, and Always use arrays for children.

  4. 4

    Copy the JSON

    Choose the indent and copy or download converted.json.

Features

Attributes kept

Every attribute, including namespace declarations such as xmlns:pay, becomes a prefixed key.

Repeats become arrays

Two or more sibling elements with the same name are collected into an array.

Careful number parsing

Values with leading zeros such as PIN codes stay strings even when parsing is on.

CDATA decoded

CDATA content is read as ordinary text, so 5 < 6 & fragile arrives unescaped.

Namespaces kept in names

Prefixed elements keep their prefix, for example "pay:status".

Local

Your browser’s own XML parser does the work.

Who uses it — and for what

Accountants and ERP users

Inspect XML exports from billing or inventory software.

Front-end developers

Consume legacy SOAP or XML APIs in JavaScript.

Feed readers

Turn RSS or Atom feeds into JSON for scripts.

Integrators

Map partner XML onto JSON-based systems.

Conversion rules

Each element becomes a key. An element with only text becomes a simple value (<age>31</age> → "age": 31). Repeated sibling elements become an array, attributes become keys with the prefix you choose (@id), and mixed text next to child elements is kept under #text. Namespaces stay in the key names (soap:Body). Ticking “always use arrays” makes the shape predictable when an element can appear once or many times — handy for code that processes the JSON.

Typical uses

Convert SOAP or legacy XML API responses for a JavaScript front end, RSS feeds for processing, Android or Maven files for inspection, or XML exports from accounting and e-commerce systems. Number and boolean parsing turns "42" into 42 and "true" into true; switch it off to keep every value as a string, exactly as written in the XML. Need the reverse? See JSON to XML.

Everything runs in your browser — your code and data are never uploaded, so it is safe to paste private config files and API responses.

Why the same XML can produce different JSON shapes

XML has no idea of “a list with one item”. If a feed sometimes contains one <item> and sometimes three, the default conversion produces an object in the first case and an array in the second. Code written against one shape then breaks on the other — a very common bug when consuming XML APIs from JavaScript.

Two ways to deal with it:

  • Tick “Always use arrays for children”. Every child element becomes an array, even when it appears once. Access is always order.item[0], which is verbose but predictable.
  • Normalise in code. Keep the compact default and wrap values that may repeat, e.g. [].concat(order.item), only where your code expects a list.

The root element is the exception: it is always a single object under its own name, such as {"order": {…}}.

Losses to expect from any XML-to-JSON conversion

XML featureWhat happens
Mixed content (text with inline tags)Text pieces are joined under #text; inline elements become keys; order is lost
Element order among different siblingsNot represented — JSON object keys carry no meaning by order
Comments and processing instructionsDropped
Whitespace around textTrimmed (CDATA text is kept as written)
Namespace URIs on prefixed elementsOnly the prefix survives in the key; the URI appears only where the xmlns attribute was declared
Data typesGuessed from the text when parsing is on; XML itself has none without a schema

For data-style XML (records, settings, API responses) these losses rarely matter. For document-style XML such as XHTML, DocBook or Word’s internal XML, where text and tags are interleaved, a JSON conversion is not a faithful representation — process those with an XML library instead. To produce XML from JSON again, see JSON to XML.

Worked examples

An order with attributes, namespaces and CDATA

Input:

<?xml version="1.0"?>
<order id="5001" xmlns:pay="urn:example:pay">
  <customer vip="true">Ravi Kumar</customer>
  <pincode>011001</pincode>
  <item sku="TEA-250"><qty>2</qty><price>180.50</price></item>
  <note>Deliver <b>after</b> 6 pm</note>
  <pay:status>PAID</pay:status>
  <comment><![CDATA[5 < 6 & fragile]]></comment>
  <gift/>
</order>

Output with default options:

{
  "order": {
    "@xmlns:pay": "urn:example:pay",
    "@id": 5001,
    "customer": { "@vip": true, "#text": "Ravi Kumar" },
    "pincode": "011001",
    "item": { "@sku": "TEA-250", "qty": 2, "price": 180.5 },
    "note": { "b": "after", "#text": "Deliver 6 pm" },
    "pay:status": "PAID",
    "comment": "5 < 6 & fragile",
    "gift": ""
  }
}

Three details deserve attention. The PIN code kept its leading zero as text, while 180.50 became the number 180.5. The empty <gift/> became an empty string. And the mixed content in note was split: the text pieces were joined into "Deliver 6 pm" and the bold word moved to its own key, so the original word order is lost.

The same XML with arrays on and types off

With Always use arrays for children ticked and Parse numbers & booleans unticked, every child element becomes an array and every value stays text, for example "item": [{"@sku": "TEA-250", "qty": ["2"], "price": ["180.50"]}] and "@id": "5001". Attributes are never wrapped in arrays, because an element cannot repeat an attribute.

Pro tips

  • Choose the _ prefix if your JSON will be used from code where @ is awkward in property names.
  • Turn off number parsing for files with codes, IDs or version strings that must keep their exact text, like 1.10.
  • If conversion fails, run the file through the XML Validator — the converter needs well-formed XML too.

Glossary

Mixed content
An element that contains both text and child elements, such as a paragraph with a bold word.
CDATA
A section whose content is treated as plain text, so < and & need no escaping.
Namespace
A URI, declared with xmlns, that keeps element names from different vocabularies apart.

Frequently asked questions

How are attributes converted?

As keys with a prefix such as @id, alongside the child elements.

What about repeated elements?

They become a JSON array automatically.

Is there a standard XML-to-JSON mapping?

No single standard exists; these rules match common libraries like xml2js and fast-xml-parser.

What does choosing “none” as the attribute prefix do?

Attributes become plain keys like "id". If an attribute and a child element share a name, they can collide, so a prefix is safer.

Why is xmlns listed as an attribute?

Namespace declarations are attributes in XML, so they are converted like any other attribute.

Are entities like &amp; decoded?

Yes. The browser’s XML parser decodes standard entities, so the JSON holds the real characters.

Found it useful? Share the XML to JSON:

Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Developer & Web (77 tools)