Skip to content

XML to JSON Converter

Paste an XML document and get clean JSON you can explore as a tree. Repeated tags become arrays, attributes are kept under @_ keys, and malformed XML is reported with a line and column. Nothing leaves your browser.

Loading editor...
Paste XML
Loading editor...
Output
Auto-run ON

How to convert XML to JSON

  1. Paste your XML into the left panel, upload an .xml file, or load it from a URL.
  2. The JSON appears on the right as you type. Leave Keep attributes ticked to carry attributes over as "@_name" keys, or untick it to drop them.
  3. Untick Detect numbers/booleans if values such as product codes or zip codes must stay strings.
  4. Switch the output to Tree to explore a large document, then click Copy or Download .json.

If the XML is not well-formed, the error bar explains the problem with a line and column, for example a closing tag that does not match the one that was opened.

What the output looks like

Input:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101" lang="en">
    <title>JSON at Scale</title>
    <price>29.99</price>
    <tags><tag>data</tag><tag>api</tag></tags>
  </book>
  <book id="bk102">
    <title>Structured Logging</title>
    <price>18.50</price>
  </book>
</catalog>

Output:

{
  "catalog": {
    "book": [
      {
        "title": "JSON at Scale",
        "price": 29.99,
        "tags": { "tag": ["data", "api"] },
        "@_id": "bk101",
        "@_lang": "en"
      },
      {
        "title": "Structured Logging",
        "price": 18.5,
        "@_id": "bk102"
      }
    ]
  }
}

The root element becomes the single top-level key. The two book siblings become an array, price turns into a number, and attributes sit beside child elements with the @_ prefix so they cannot collide with a child named id.

The single-child gotcha

Repeated sibling tags become an array, but a tag that appears once becomes an object. If the catalog above held one book, book would be an object rather than a one-element array, and code such as catalog.book.map(...) would break on that document. XML has no way to say "a list of one", so the converter cannot know. Wrap the value with [].concat(data.catalog.book) in your code, or have the producer emit a fixed wrapper element. JSON array vs object covers the distinction in more depth.

Limits and notes

  • Files up to 5 MB. Parsing runs as JavaScript in your browser; nothing is uploaded.
  • Comments, processing instructions, and the XML declaration are dropped. Namespace prefixes stay as part of the key, for example "soap:Body".
  • Mixed content (text beside child elements) is collected under a #text key; whitespace between elements is trimmed.
  • Empty elements such as <note/> become empty strings, not null.
  • Type detection follows numeric rules, so 18.50 becomes 18.5 and 02134 becomes 2134. Turn it off when the exact text matters.
  • Repeated tags are how XML expresses what JSON would reject as duplicate keys; the array is the faithful translation. For the wider trade-offs, see JSON vs XML, and use JSON to XML for the reverse direction.

Frequently Asked Questions

Where did my attributes go?
With Keep attributes ticked, each attribute becomes a key prefixed with @_ next to the element's children, so id="bk101" becomes "@_id": "bk101". Untick the option to drop attributes entirely.
Why is one element an object but two are an array?
XML cannot say that a tag is a list of one. Repeated sibling tags become an array, while a tag that appears once becomes an object. Normalise in your code with [].concat(value) if the count can vary.
Why did 02134 turn into 2134?
Detect numbers/booleans converts anything that looks numeric. Untick it when zip codes, product codes, or IDs with leading zeros must stay strings; true and false then stay strings too.
What happens to text mixed with child elements?
Plain JSON has no mixed content, so text that sits beside child elements is collected under a #text key. If the layout of that text matters, keep the XML and query it with XPath instead.
Is my data uploaded?
No. Parsing and conversion run as JavaScript in your browser tab, so the XML never leaves your machine.

Guides that go with this tool

More JSON tools

JSON Viewer (Tree View)

Explore any JSON document as a collapsible tree in your browser. Click a key to copy its JSONPath, click a value to copy it, and page through large arrays without freezing the tab.

JSON Fixer: Repair Invalid JSON

Repair broken JSON in your browser. Strips markdown fences and prose, fixes trailing commas, single quotes, comments, unquoted keys, Python literals and unclosed brackets, and lists every problem it detected.

JSON to CSV Converter

Convert a JSON array of objects to CSV in your browser. Nested objects are flattened to dotted columns, values are quoted correctly, and Excel-friendly output is one click away.

CSV to JSON Converter

Convert CSV with a header row into a JSON array of objects in your browser. Numbers and booleans are detected, leading-zero codes stay strings, and the delimiter is picked up automatically.

JSON to YAML Converter

Convert JSON to clean YAML in your browser with 2, 3 or 4 space indentation. Strings that a YAML parser would read as numbers, booleans or dates are quoted so they survive the round trip.

YAML to JSON Converter

Convert YAML to JSON in your browser. Multi-document files become an array, anchors and aliases are resolved, and only null, true, false and plain numbers are typed, so yes, NO and dates stay strings.

JSON to XML Converter

Convert JSON to XML in your browser. Choose the root and array item element names, nulls become xsi:nil, keys are sanitised into valid XML names, and text is escaped.

JSON Compare (Diff)

Compare two JSON documents in your browser and get a structural diff that lists every changed, added, and removed value with its JSONPath. Key order and whitespace are ignored.

JSONPath Query Tester

Test JSONPath expressions against your JSON in the browser. Pick an expression, see the matches as a JSON array with a count, and explore the results in tree view.

JSON Escape / Unescape

Escape text into a JSON string literal, unescape one back to plain text, or stringify a whole JSON document to embed it inside another JSON value or in source code.