Convert · XML to JSON

Convert XML to JSON

Paste XML and get readable JSON — attributes, nested elements, repeated tags, and mixed text handled automatically. Runs in your browser.

No sign-up to start · Runs in your browser

XML to JSON
Open the JSON in the editor
XML
JSON

Runs entirely in your browser — nothing is uploaded.

<order id="ord_9412">
  <total>184.5</total>
  <items>
    <item sku="tee">2</item>
    <item sku="mug">1</item>
  </items>
</order>
An XML-to-JSON converter reads an XML document and returns equivalent JSON. JSON Copilot maps each attribute to a key prefixed with "@", turns repeated sibling tags into arrays, stores text under a "#text" key when an element also has attributes, and coerces numbers and booleans — all in your browser with the built-in XML parser, so nothing is uploaded. Paste XML below to get clean, readable JSON, then open the result in the full editor to format, validate, or visualize it.

XML to JSON: a worked example

XML input
<book id="bk-204">
  <title>Deep Work</title>
  <author>Cal Newport</author>
  <tags>
    <tag>focus</tag>
    <tag>habits</tag>
  </tags>
  <price currency="USD">18.5</price>
</book>
JSON output
{
  "book": {
    "@id": "bk-204",
    "title": "Deep Work",
    "author": "Cal Newport",
    "tags": {
      "tag": [
        "focus",
        "habits"
      ]
    },
    "price": {
      "@currency": "USD",
      "#text": 18.5
    }
  }
}

The root element becomes the single top-level key. Attributes turn into "@" keys, the two <tag> siblings collapse into an array, and <price> — which carries both an attribute and text — keeps its value under "#text". The id stays a string while 18.5 is coerced to a number.

How to convert XML to JSON

  1. 1

    Paste your XML

    Drop well-formed XML into the input — or start from the loaded example. Every tag must close and the document needs a single root element.

  2. 2

    Convert to JSON

    Elements become keys, attributes become "@name" keys, and sibling tags that repeat collapse into arrays. Text content is read as the value.

  3. 3

    Check the mapping

    Confirm attributes landed under "@" keys and that repeated elements became arrays. Values like 184.5 are coerced to numbers automatically.

  4. 4

    Fix any parse error

    If the XML is malformed, the tool reports the first error instead of guessing — escape stray & characters or close the open tag, then re-run.

  5. 5

    Open the JSON in the editor

    Send the converted JSON straight into the full editor to format, validate, explore it as a tree or mind map, and use the AI copilot.

Why use this converter

Runs in your browser

Conversion is 100% client-side using the built-in XML parser — your XML never leaves your device, with no account and no upload.

Attributes preserved

Every XML attribute is kept as a key prefixed with "@", so attributes stay distinct from child elements and nothing is dropped.

Repeated tags become arrays

When sibling elements share a tag name, they collapse into a JSON array in document order — ready to map over in JavaScript.

Text kept alongside attributes

A leaf element that has both attributes and text stores its text under a "#text" key next to the "@" attributes, so both survive.

Smart type coercion

Numbers and true/false become real JSON values, while leading-zero and long digit ids stay strings so codes like 007 are not mangled.

Clear parse errors

Malformed XML is reported with the first error message rather than silently guessed, so you can find and fix the problem fast.

How XML maps to JSON

The converter walks the XML tree with the browser’s built-in parser and produces one JSON object whose single top-level key is the document’s root element. Each child element becomes a key, and its value is whatever the element contains: a scalar for text-only nodes, or a nested object for elements that have their own children or attributes.

Attributes become keys prefixed with an "@" sign. An element like <price currency="USD"> yields "@currency": "USD". Prefixing keeps attributes in the same object as their element while staying clearly separate from child-element keys, so an attribute and a child that happen to share a name never collide.

When an element carries both attributes and text on the same node, the text is stored under a "#text" key next to the "@" attributes. That is how <price currency="USD">18.5</price> becomes { "@currency": "USD", "#text": 18.5 } rather than losing either half of the information.

Text values are type-coerced on the way in: 184.5 becomes a JSON number and true or false become booleans. Identifiers with leading zeros or very long digit runs are deliberately kept as strings, so an id like 007 or a 20-digit account number survives intact instead of being silently rounded.

Where XML to JSON gets ambiguous

XML and JSON do not share a data model, so any conversion has to make choices — and the biggest is single-versus-array. XML has no way to say "this is a list that happens to hold one item." When a tag appears once the converter emits it as a single value — a scalar or an object; the moment a second sibling with the same tag appears, that key becomes an array.

The practical consequence is that the output shape depends on the data, not on a schema. <items><item>2</item></items> makes "item" the single value 2, while adding one more <item> makes "item" an array. If your consuming code iterates, normalize defensively: wrap a lone value in an array before you map over it.

Mixed content — text interleaved with child elements, like <p>See <b>here</b> now</p> — has no clean JSON equivalent. Once an element has child elements the converter keeps only those children and drops the loose text around them, so "See" and "now" would vanish. The "#text" key rescues text only on a leaf element that also carries attributes, not on elements that contain other tags. Document-style XML that blends markup and prose round-trips far worse than record-style data XML.

Attribute-versus-element is a third modeling gap: the same fact can be written as <price currency="USD"> or as <price><currency>USD</currency></price>, and the two produce different JSON. If you control the XML, pick one convention upstream so downstream code does not have to handle both.

Consuming XML APIs and feeds in JavaScript

A great deal of data still ships as XML: RSS and Atom feeds, sitemaps, SOAP responses, SVG, Office Open XML documents, and plenty of older enterprise APIs. JavaScript speaks JSON natively, so converting first lets you use dot access, destructuring, Array.map, and JSON.stringify instead of manually walking a DOM tree.

A common flow is to fetch a feed, convert a representative sample here to see its shape, then write code against the result — for instance reading rss.channel.item as an array of entries. Seeing the converted structure first removes the guesswork about which tags repeat and which values live in attributes versus text.

For configuration and fixtures, turning an XML file into JSON gives you something you can drop into a test, a JSON config, or a document database. Because the conversion is entirely client-side, you can paste internal or sensitive XML to inspect its shape without it ever leaving your machine.

Once you have the JSON, the full editor is where you actually work with it: format and validate it, expand it as a collapsible tree or a mind map to understand deep nesting, and ask the AI copilot to reshape, filter, or explain the structure before you build against it.

Tips for a clean conversion

Start with well-formed XML. The browser parser is strict: every tag must close, attribute values must be quoted, and the document needs exactly one root element. Malformed input is reported as a parse error rather than silently repaired, so fix the first error the tool names and convert again.

Escape reserved characters inside text — write & as &amp;, < as &lt;, and > as &gt;, or wrap the text in a CDATA section. An unescaped ampersand is the single most common cause of parse failures in hand-written or string-concatenated XML.

Mind the edges that XML and JSON handle differently. Namespace prefixes are preserved in key names, so <ns:tag> becomes "ns:tag"; comments and processing instructions are discarded. If a value must stay a string — a ZIP code, a version like 1.0, or an id with leading zeros — be aware that plain numeric text is coerced to a number unless it has a leading zero or is very long.

Finally, convert a sample that actually contains the repeating case. Because a lone element becomes an object and repeated siblings become an array, a one-item sample can hide the array shape your production data will produce — so test against data that includes at least two of the repeating element.

Frequently asked questions

Is the XML to JSON converter free and private?

Yes. It runs entirely in your browser using the native XML parser, with no account and no upload — your XML never leaves your device.

How does it map XML attributes to JSON?

Each attribute becomes a key prefixed with "@". So <price currency="USD"> yields "@currency": "USD", which keeps attributes distinct from child elements and loses no information.

How are repeated elements handled?

When an element has multiple children with the same tag, they collapse into a JSON array in the order they appear. A single occurrence stays a lone value — a scalar or object — and is never wrapped in an array.

What happens to text inside an element that also has attributes?

The text is stored under a "#text" key alongside the "@" attributes. For example <qty unit="kg">5</qty> becomes { "@unit": "kg", "#text": 5 }.

Why did a repeated element come out as a single value instead of an array?

XML cannot express a list of one. An element that appears once comes out as a single value — a scalar or an object — and only switches to an array once a second sibling with the same tag appears. If your code expects a list, normalize the single value into an array before iterating.

What is the difference between XML and JSON?

XML is a markup language with elements, attributes, namespaces, and mixed content; JSON is a lightweight data format of objects, arrays, strings, numbers, booleans, and null. JavaScript reads JSON natively, so converting first replaces DOM walking with plain property access.

Does it support namespaces, comments, and CDATA?

Namespace prefixes are kept as part of the key (<ns:tag> becomes "ns:tag"), and CDATA text is read as a normal value. Comments and processing instructions are dropped — only elements, attributes, and text carry into the JSON.

Where does the converted JSON go?

The result appears in the tool right away. From there you can open it in the full editor to format, validate, explore it as a collapsible tree or mind map, and use the AI copilot.

Related tools

Convert your XML to JSON

Open the Editor