Skip to main content
KalkuNet

XML to JSON — Converter with Attributes, CDATA, Namespaces and DTD Entities

Parse XML tags, attributes & nested child elements into JSON objects.

Runs in your browserDeveloper · JSON, YAML, TOML, XML & CSV Converters
JSON indent:
  • The mapping follows xmltodict: attributes become "@name", text next to attributes or child elements becomes "#text", repeated elements become an array, empty elements become null and every value is a string. Comments and processing instructions are left out.

When to use the XML Document to Structured JSON Converter

  • A familiar format

    The mapping follows Python's xmltodict: attributes become "@name", text next to child elements becomes "#text" and repeated elements turn into arrays. The output is tested to match xmltodict exactly.

  • A complete XML parser

    The parser passes all 1724 XML 1.0 Fifth Edition cases of the W3C XML Conformance Test Suite, including the newer name-character rules that expat still fails.

  • Entities and DTD defaults

    Entities declared in the internal subset are expanded, default attributes from <!ATTLIST> are included, and expansion stops at 10 million characters so a “billion laughs” document cannot freeze the browser.

  • Errors with a location

    Documents that are not well-formed are rejected with the line, the column and an explanation, such as a mismatched closing tag, an & without an entity or an undeclared namespace prefix.

Frequently asked questions

Are numbers turned into JSON numbers?

No. XML has no data types, so every value is written as a string, just like xmltodict does.

What about comments and processing instructions?

Neither is carried into the JSON. Use the XML formatter to tidy a document while keeping them.

What does the trim option change?

When it is on, white space and line breaks around text are removed, as xmltodict does by default. When it is off, text is written in full, including the indentation between child elements.

How are namespaces handled?

Names are kept as written, such as atom:link, and xmlns declarations appear as attributes. The namespace check rejects prefixes that are not declared.

Is my data uploaded?

No. Parsing and conversion run in your browser.

Learn more