XML to JSON — Convert XML Documents to JSON Online

🔒 Runs in your browser — nothing is sent to a server

XML to JSON converts any XML document — a SOAP envelope, an SVG file, an Office Open XML part, an RSS feed, an Android layout — into a clean JSON tree in one click. Paste the XML, and this XML to JSON converter parses it with the AST-based `fast-xml-parser` library, maps attributes to keys prefixed with `@`, mixed text content to `#text`, and emits pretty-printed JSON ready for an API call, a JavaScript transform or a config import. Number and boolean parsing, namespace preservation and array coercion are all toggleable. Everything runs 100% inside your browser; your XML never leaves your device, nothing is uploaded, logged or sent to any server.

Convention: attributes are prefixed with @, mixed text content uses #text.

Two-pane view: input and output side by side
Copied!

When to use an XML to JSON converter online

You reach for an XML to JSON converter any time XML-shaped data needs to flow into a JSON-native pipeline: parsing a SOAP response from a legacy enterprise service, ingesting an RSS or Atom feed into a JSON-store, transforming an SVG into a programmatic representation, importing an Android layout into a documentation tool, or feeding an Office Open XML part to a JavaScript validator. Browser-local conversion matters when the XML carries SAML assertions, signed envelopes, customer-facing payloads or any sensitive data you would rather not paste into a remote SaaS converter.

How XML to JSON conversion works under the hood

XML to JSON conversion is a parse-then-emit pipeline. The fast-xml-parser tokenizer reads the source character by character, recognising the XML declaration, DOCTYPE, opening and closing tags, attributes, text nodes, CDATA sections, comments and processing instructions. The parser builds an in-memory tree that mirrors the document structure; attributes attach to each tag, mixed text content uses the `#text` key, and tags with two or more same-named siblings collapse into a JSON array. Number and boolean parsing runs each value through a typed-coercion check, namespaces are preserved or stripped per option, and the resulting tree is serialised with `JSON.stringify(value, null, 2)` — pretty-printed and ready to copy into a fixture file or paste into Postman. The whole pipeline runs inside the browser engine in milliseconds, even on multi-megabyte XML payloads.

Examples

Input
<?xml version="1.0" encoding="UTF-8"?>
<book id="1" available="true">
  <title>Atlas</title>
  <author>A. Reyes</author>
  <year>2024</year>
</book>
Output
{
  "book": {
    "@id": 1,
    "@available": true,
    "title": "Atlas",
    "author": "A. Reyes",
    "year": 2024
  }
}
XML to JSON — typical document with attributes and child elements
Input
<catalog>
  <book id="1"><title>Atlas</title></book>
  <book id="2"><title>Vesper</title></book>
  <book id="3"><title>Beacon</title></book>
</catalog>
Output
{
  "catalog": {
    "book": [
      {
        "@id": 1,
        "title": "Atlas"
      },
      {
        "@id": 2,
        "title": "Vesper"
      },
      {
        "@id": 3,
        "title": "Beacon"
      }
    ]
  }
}
Convert XML to JSON — repeated children become a JSON array
Input
<tool>
  <name>xml to json</name>
  <role>parse xml to json with attribute mapping</role>
  <client>free-converter.online</client>
</tool>
Output
{
  "tool": {
    "name": "xml to json",
    "role": "parse xml to json with attribute mapping",
    "client": "free-converter.online"
  }
}
XML json converter — payload that names the tool itself
Input
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
  <circle cx="12" cy="12" r="10"/>
</svg>
Output
{
  "svg": {
    "@xmlns": "http://www.w3.org/2000/svg",
    "@viewBox": "0 0 24 24",
    "circle": {
      "@cx": 12,
      "@cy": 12,
      "@r": 10
    }
  }
}
Parse XML to JSON — namespaces and mixed content preserved

FAQ

How do I convert an XML document to JSON?

Paste the XML into the input above and click Convert to JSON. The converter validates the source with `XMLValidator`, parses it with the `fast-xml-parser` library, maps attributes to keys prefixed with `@`, mixed text content to `#text`, and emits a pretty-printed JSON tree. Errors surface with the offending line and column.

How are XML attributes represented in the JSON output?

XML has three concepts — attributes, text content, child elements — that JSON has to flatten into key-value pairs. This converter prefixes attribute keys with `@` (so `<a href="x">` becomes `{"a": {"@href": "x"}}`) and uses `#text` for text content when an element has both attributes and inner text. Other conventions exist (Badgerfish, Parker, JsonML) but the `@` / `#text` pair is the most common in modern tooling.

When does a child element become an array vs. a single object?

By default an array appears only when a tag has two or more siblings with the same name — `<book>...</book><book>...</book>` becomes `"book": [{...}, {...}]`. A single `<book>...</book>` stays an object. Turn on "Always make arrays" to coerce every element into an array; useful when downstream JavaScript expects a uniform shape.

Will the XML to JSON converter preserve namespaces?

Yes by default. `xmlns:ns="http://example.com"` declarations and `ns:` prefixes are kept verbatim on tag names and attribute names. Turn off "Preserve namespaces" to strip the `ns:` prefix and emit a flatter JSON tree — useful when downstream consumers do not care about XML namespaces and you want shorter keys.

How does parsing of numbers and booleans work?

With "Parse numbers and booleans" on (default), the converter runs each tag value and attribute value through a numeric and boolean check: `"42"` becomes the JSON number `42`, `"3.14"` becomes `3.14`, `"true"` and `"false"` become booleans. Turn it off when your XML contains values that look like numbers but should stay strings — phone numbers, ZIP codes, SKUs with leading zeros, version strings.

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

CDATA contents are merged into the surrounding text node by default. Comments are stripped because JSON has no comment syntax. The `<?xml version="1.0"?>` declaration is dropped by default (toggle "Ignore XML declaration" off to keep it). The DOCTYPE declaration is parsed but its internal subset is ignored.

How is XML to JSON different from JSON to XML?

XML to JSON and JSON to XML are inverse operations under the same convention (`@` for attributes, `#text` for mixed text). XML to JSON parses a tag-oriented document into a key-value tree for JavaScript consumption. JSON to XML serialises a key-value tree back into XML for SOAP, SVG or any XML-native consumer. Round-trips cleanly when both tools share the same convention settings.

Is it safe to paste sensitive XML into this XML to JSON converter online?

Yes — the XML to JSON converter runs entirely in your browser via the `fast-xml-parser` library bundled into the page. Your XML and the JSON output stay on your machine; nothing is uploaded, logged or cached. Safe for SOAP envelopes containing tokens, SAML assertions, signed payloads, internal config files and any XML you would not want a remote SaaS converter to retain.

Glossary

XML (Extensible Markup Language)

XML is a text-based, tag-oriented format defined by the W3C XML 1.0 spec. It powers SOAP and WS-* web services, RSS and Atom feeds, Office Open XML (`.docx`, `.xlsx`), Android layouts, SVG and countless legacy enterprise systems. Converting XML to JSON gives every node a key-value shape that JavaScript and modern HTTP APIs can consume directly.

JSON (JavaScript Object Notation)

JSON is a lightweight, text-based data format that represents structured data as nested objects, arrays, strings, numbers, booleans and null. Defined by RFC 8259 and ECMA-404, JSON is the de-facto wire format for HTTP APIs and configuration files. XML to JSON conversion lets XML-native systems (SOAP services, legacy data feeds) feed into JSON-native pipelines.

XML attribute

An XML attribute is a name-value pair inside the opening tag — for example the `id` and `available` in `<book id="1" available="true">`. Attributes are usually metadata about the element, while child elements hold the data itself. A correct XML-to-JSON converter must distinguish attributes from children; this tool prefixes attribute keys with `@` (so `id` becomes `@id`) to keep the two namespaces separate.

Mixed content

Mixed content is an XML element that holds both text and child elements — for example `<p>Hello <b>world</b>!</p>`. In JSON the text and children share the same level, so a converter needs a convention: this tool maps the text portion to a `#text` key alongside the child element keys. Without `#text` the text would silently disappear into the JSON tree.

XML namespace

An XML namespace is a URI-anchored prefix that disambiguates element names across vocabularies — `xmlns:dc="http://purl.org/dc/elements/1.1/"` lets `<dc:title>` mean "Dublin Core title" rather than any `<title>`. A correct XML-to-JSON converter preserves the prefix on the JSON key (`"dc:title"`) by default so downstream consumers can still tell vocabularies apart.

fast-xml-parser

fast-xml-parser is the de-facto JavaScript XML library — a single-pass tokenizer with configurable attribute prefixes, array coercion, namespace handling and number parsing, plus a matching `XMLBuilder` for the inverse direction. It powers countless XML-handling Node and browser apps and is small enough to bundle into a client-side tool. Browser-local parsing means the XML never leaves the page.

Related tools