Tools / Text & Data / XML to JSON
Client-side

XML to JSON

Convert XML documents to JSON locally in your browser, mapping nested elements and attributes to objects ready for API testing or schema migration.

What it does

  • Attributes prefixed with @, text content under #text
  • Repeated sibling elements grouped into arrays
  • Parse errors reported with their position
  • No toolchain required, runs entirely in the browser
  • Copyable JSON output

Paste an XML document, click XML → JSON, and get a pretty-printed JSON object you can copy. The conversion follows a fixed, documented mapping (described below), so you can predict the output shape before you write code against it. Parsing is done by quick-xml, a Rust XML parser compiled to WebAssembly, which means SOAP responses, invoices and data exports are converted inside your browser tab without being uploaded. This page and the XML to JSON conversion guide use the same engine; the guide focuses on when converting XML to JSON is the right move.

How XML maps to JSON

XML has concepts JSON does not (attributes, mixed text, repeated tags), so every converter has to choose a convention. This one uses the widely recognized @ and #text convention:

  • Root element: the output is an object with a single key, the name of the root element. <order>...</order> becomes {"order": {...}}.
  • Child elements become keys of their parent object.
  • Attributes become keys prefixed with @: <item id="7"> gives "@id": "7".
  • Text-only elements become plain strings: <city>Lyon</city> gives "city": "Lyon".
  • Text plus attributes: the text goes under #text, next to the @ keys.
  • Repeated siblings with the same name are grouped into an array: two <item> elements give "item": [{...}, {...}].
  • Empty elements such as <note/> become null.

One consequence to plan for: a single <item> becomes an object, while two or more become an array. If the number of items varies between documents, your code should accept both shapes.

How to convert XML to JSON

  1. Paste the XML into the left panel. The XML declaration (<?xml ...?>) and comments can stay; they are skipped.
  2. Click XML → JSON.
  3. Read or copy the JSON in the right panel. If the XML is malformed, the status line shows the error and its position, for example a closing tag that does not match the opening one.

Limits and edge cases

  • All values are strings. <qty>42</qty> becomes "42", and true stays the string "true". XML carries no type information without a schema, so nothing is guessed.
  • CDATA sections are not included. Content inside <![CDATA[...]]> is skipped, and an element containing only CDATA comes out as null. If your feed wraps HTML in CDATA, extract it separately.
  • Mixed content loses spacing. In <p>Hello <b>you</b> there</p>, the text pieces are joined under #text without the spaces around the inner element, and the inner element becomes its own key. The converter is designed for data XML, not for document markup like XHTML.
  • Namespaces are kept as written. Prefixed names stay prefixed ("soap:Body"), and namespace declarations appear as attributes ("@xmlns:soap").
  • Entities are decoded. &amp; in text becomes & in the JSON string.
  • One direction only. The tool converts XML to JSON; it does not generate XML from JSON.

Typical uses

  • Inspecting a SOAP response before rewriting an integration against a REST API.
  • Reading an RSS or Atom feed, a sitemap, or a configuration file as a JSON tree.
  • Turning an XML export from an ERP, a bank or a public administration into data a JavaScript or Python script can load directly.
  • Getting the exact JSON shape to write types or a schema for.

Compared with code and command-line tools

In code, libraries such as xmltodict in Python or fast-xml-parser in JavaScript do this conversion with configurable options, and yq can read XML on the command line. They are the right choice for automated pipelines. This page is for the moment before that: checking what a document looks like as JSON, without setting up a project, and without sending a production payload to an online service.

Privacy for business XML

XML is still the format of banking statements, electronic invoices, health data exchanges and government APIs. Those documents carry names, account numbers, addresses and amounts. The conversion here runs in WebAssembly in your browser, with no request carrying the document, so the data stays on your machine.

Frequently asked questions

Is my XML uploaded to a server?
No. The XML is parsed and converted locally in your browser. Nothing is transmitted or stored.
Why are attributes prefixed with @?
To keep them distinct from child elements with the same name. Without a prefix, <user id="1"><id>2</id></user> would have two conflicting id keys.
Why is one element an object and another an array?
Repeated sibling elements are grouped into an array, while a single occurrence stays an object or a string. Handle both shapes in code when the count can vary.
Why are my numbers strings?
XML text has no types, so every value is kept as a string. Convert fields to numbers in your own code where it makes sense.
What happens to CDATA and comments?
Both are skipped. Comments are not data, and CDATA content is currently not carried into the JSON.
Can I convert JSON back to XML?
No, this tool works in one direction. For other format changes, the YAML, JSON and TOML converter covers configuration formats.

Related tools: once converted, tidy or minify the result with the JSON formatter, or flatten an array of records into a spreadsheet with the JSON to CSV converter.