XML Parser Online — Parse XML to JSON & Inspect Tree

Parse XML into a structured tree, surface attributes (@-prefix), text content (#text), namespaces, and CDATA. Convert to JSON in one click — entirely in your browser.

What is an XML Parser?

An XML parser takes a raw XML document and returns a structured tree your code can navigate — element names, attributes, text content, comments, and CDATA all surfaced as inspectable nodes. The OpenFormatter parser does this in your browser using the native DOMParser, then projects the tree as JSON so you can copy it into JavaScript, TypeScript, or any tool that consumes JSON.

The parser is purpose-built for the moment a backend hands you an unfamiliar SOAP response, an enterprise integration emits a custom XML format, or a legacy feed needs to be consumed in modern code. Paste, click, and the structure becomes obvious — root element, depth, repeated children grouped into arrays, attributes prefixed with @, text content under #text. No tooling install, no schema required.

How to parse XML online — 4 steps

  1. Paste your XML. Drop the document into the Input panel above. Or click Load Sample to try a library.xml example with namespaces and CDATA.
  2. Click Parse. The browser's native DOMParser walks the document and the tool projects it as JSON.
  3. Inspect the tree. The output shows root tag, total element count, unique tag list, and the full JSON tree — attributes prefixed with @, text under #text, repeated children grouped into arrays.
  4. Copy the JSON. Click Copy and paste the parsed structure into your code, fixtures, or docs.

Sample input vs. parsed JSON

Input XML

<book id="bk101" available="true">
  <title>XML Guide</title>
  <price currency="USD">44.95</price>
</book>

Parsed JSON

{
  "book": {
    "@id": "bk101",
    "@available": "true",
    "title": "XML Guide",
    "price": {
      "@currency": "USD",
      "#text": "44.95"
    }
  }
}

Element Tree

Walks the entire document and reports root tag, depth, repeated children grouped as arrays, and a unique-tag inventory — perfect for figuring out the shape of an unfamiliar payload.

XML to JSON Projection

Attributes prefixed with @, text content under #text, namespaces preserved on qualified names. The output is round-trippable through xml2js and fast-xml-parser conventions.

Client-Side Parser

Uses the browser's native DOMParser. No upload, no external entity expansion (XXE-safe by default), no rate limits — verify with DevTools Network.

Common use cases

  • check_circleInspecting an unfamiliar SOAP response before writing client-side bindings
  • check_circleReverse-engineering a legacy XML feed when the schema or documentation is missing
  • check_circleConverting XML test fixtures to JSON for use in modern unit tests
  • check_circleDumping the structure of a vendor's XML export to plan a database schema
  • check_circleNavigating a deeply nested config file to find a specific element's path
  • check_circleBuilding a JSON-equivalent payload from an XML reference document for an API migration
  • check_circleExploring RSS, Atom, and Sitemap.xml feeds to understand element conventions
  • check_circleSpotting attribute vs. element conventions in third-party XML before integration

Parser vs. validator vs. converter

An XML validator answers a yes/no question: is this document well-formed? An XML to JSON converter produces a JSON file ready for download. The parser sits between the two: it gives you the parsed structure plus inspectable metadata (root tag, total elements, unique-tag set, JSON projection) in one panel. Reach for the parser when you need to understand the document, not just convert it.

Need more than parsing?

Validate, format, view, or convert XML with the rest of OpenFormatter's XML toolkit — all browser-side.

Frequently Asked Questions

How are XML attributes represented in the parsed tree?

Attributes are prefixed with "@" in the JSON output. So <book id="bk101" available="true"> becomes { "@id": "bk101", "@available": "true" }. This is the same convention used by xml2js, fast-xml-parser, and most JSON-XML bridges, which keeps the output round-trippable and avoids name collisions between attributes and child elements.

What about namespaces?

Namespace prefixes are kept on the qualified element name — <dc:title> appears in the parsed tree as "dc:title". Namespace declarations (xmlns:dc="...") show up as @-prefix attributes on the element where they're declared. The DOMParser used under the hood is XML-namespace-aware, so prefix resolution follows the W3C spec.

How does the parser handle CDATA?

CDATA sections are unwrapped — the parser reads their content as text and surfaces it as a #text value on the parent element. So <description><![CDATA[<em>bold</em>]]></description> parses as { "description": "<em>bold</em>" }. The literal characters inside CDATA are preserved exactly, which matters for HTML fragments embedded in XML.

What's the difference between this parser and the XML validator?

The validator confirms a document is well-formed and stops — it answers "yes/no, valid?". The parser goes further: it returns the parsed structure (tree, JSON, attribute map) so you can inspect or consume it. Use the validator when you only need the verdict; use the parser when you also want to see the shape of the data.

Mixed content with text and child elements — what happens?

When an element contains both text and children (e.g. <p>Hello <b>world</b>!</p>), the parser stores the text under "#text" and the child elements under their tag names. You may lose the original interleaved order in the JSON form — for round-trip fidelity, work with the XML tree directly rather than the JSON projection.

Can it parse documents over the network?

No — the parser only handles XML you paste into the input panel. It does not fetch URLs, follow xinclude references, or expand external entity declarations. That last one is intentional: external entity expansion is the basis of XXE attacks, which the browser DOMParser blocks by default.

Are repeated elements grouped into arrays?

Yes. When the parser encounters two or more siblings with the same tag name (e.g. multiple <book> children), it collects them into a JSON array. A single occurrence stays as an object — same heuristic xml2js and fast-xml-parser use. If you need consistent array behaviour for downstream code, post-process the result.

Does the parser send my XML anywhere?

No. The browser's native DOMParser handles everything client-side. No HTTP request fires when you click Parse — verifiable via the DevTools Network tab. That matters when the document contains customer data, API tokens, internal endpoint URLs, or any payload that cannot leave your network.

XML Parser Online — Parse XML to JSON & Inspect Tree