🗂️ XML to JSON Converter
Paste XML and get JSON — attributes keep an @ prefix, repeated sibling elements become arrays, and parse errors are reported plainly.
✗ DOMParser is not defined
How the xml to json converter works
Parsing uses the browser’s native DOMParser — the same engine that renders XML in web pages — so well-formedness rules are enforced exactly. The mapping convention: element attributes become "@name" keys, text content of mixed elements becomes "#text", and repeated sibling elements (like the two <book> entries in the sample) collapse into a JSON array.
XML-to-JSON has no single canonical mapping — attributes and repeated elements force conventions. Ours matches the common "@/#text" style used by most tooling, and keeps values typed (the year 1965 arrives as a number). Feeds (RSS), SOAP payloads and legacy exports are the usual customers.
Frequently asked questions
How are attributes represented?
As keys prefixed with @: <book id="1"> becomes {"@id": 1, ...} — the widely used convention that keeps attributes distinguishable from child elements.
Why is one <item> an object but two <item>s an array?
JSON has no repeated keys, so single children map to objects and repeated siblings to arrays. Code consuming varying feeds should handle both shapes — or normalize afterward.
Why does my XML fail to parse?
DOMParser enforces well-formedness: every tag closed, one root element, & escaped as &. The error message quotes the parser’s reason, usually with a line reference.
Are namespaces supported?
Tags keep their prefixed names (ns:tag) as-is — namespace semantics beyond naming are not interpreted, which suits most conversion needs.
Is my XML kept local?
Yes — parsing happens in your browser with nothing transmitted.
Related file converters
From the blog
-
Received an Invoice as an XML File? XRechnung and ZUGFeRD Explained
Germany's B2B e-invoicing mandate means invoices now arrive as XRechnung XML or ZUGFeRD hybrid PDFs. What the formats are, why you're getting them, the 2025–2028 timeline, and how to actually read one.
-
JSON vs YAML vs XML: Which Data Format for Which Job
APIs speak JSON, humans edit YAML, legacy systems demand XML. How the three formats differ, when each wins, the Norway problem, and how to convert between them without losing data.