XML Parser

Parse XML into a tree and a JSON object.

Tree view
The tree appears here. Paste XML or click Sample.

XML Parser Online

The XML parser reads a document the way a program would and shows you the result: a tree of elements, attributes, and text, plus the equivalent JSON object. It is a quick way to answer questions like “which elements repeat?”, “is this value an attribute or a child element?”, or “what will my code actually receive after parsing?”.

What happens during parsing

The input is tokenized into the XML declaration, comments, CDATA sections, processing instructions, and elements. Entities such as &, <, and numeric references like © are decoded to the characters they represent. Every opening tag must be matched by the right closing tag and attribute values must be quoted; the first violation stops the parser with a line and column number.

Parsed as JSON

Below the tree, the parsed data is printed as JSON using a widely used convention:

  • the root element becomes the single top-level key;
  • attributes become @name keys;
  • text of an element with attributes goes to #text;
  • sibling elements with the same name are grouped into an array;
  • numbers and booleans are detected automatically.

Copy or download the JSON to use it as a fixture, or to understand how libraries such as xml2js and fast-xml-parser will shape your data.

Reading the result

Compare the tree with the JSON to see decisions a parser makes for you: whitespace between elements is dropped, a single <book> becomes an object while three become an array, and namespace prefixes such as dc: stay part of the key. Knowing this in advance avoids the classic bug where code works with one record and fails with two.

Parser, validator, or converter?

This page is for exploring and understanding a document. If you only need a yes/no answer on syntax, the XML Validator is more direct. If you need control over the JSON shape — attribute prefixes, text keys, namespace stripping — use XML to JSON.

Query the parsed document with the XPath Tester, view it in the XML Viewer, or parse JSON instead with the JSON Parser.

Frequently Asked Questions

Two things: a navigable element tree and a JSON representation of the same data. In the JSON, attributes become keys with an @ prefix, element text is stored under #text when the element also has attributes, and repeated elements become arrays.

The parser detects types, so text such as 44.95 or true becomes a JSON number or boolean. Values with leading zeros like 007 stay strings. If you need every value as a string, use the XML to JSON converter and switch type detection off.

The parser stops at the first problem and reports the line and column, for example “Closing tag </a> does not match <b> opened on line 1”. No JSON is produced until the document is well-formed.