XML to JSON
Convert an XML document into an equivalent JSON structure — attributes, nesting, and repeated elements preserved. Runs entirely in your browser, no upload.
About this tool
XML to JSON converts an XML document into an equivalent JSON structure, keeping the shape of your data intact: attributes, nested elements, and repeated tags all map predictably to JSON. Paste your XML and get clean, pretty-printed JSON back — everything runs locally in your browser, so nothing is uploaded.
How the conversion works
- Elements become JSON objects keyed by their tag name. The document's single root element becomes the only top-level key.
- Attributes become object members prefixed with
@by default (soid="1"becomes"@id": "1"). Change the prefix, or turn attributes off entirely. - Repeated sibling tags collapse into a JSON array, in document order — so
three
<book>elements become a"book": [ … ]array. - Text content of a simple element becomes a plain string. When an element
has both text and attributes or children, its text is stored under a
configurable key (
#textby default). - Entities and CDATA are decoded, comments and processing instructions are ignored, and namespace prefixes are reduced to their local names.
Type coercion
By default every value stays a string, which is the safest round-trip. Enable
"Coerce numbers, booleans, and null" to turn text like 42, 1.5, true, and
null into the matching JSON scalar. Leading-zero strings such as 007 are kept
as strings so identifiers are never mangled.
Private and offline
The conversion runs entirely in your browser via WebAssembly. Your XML never leaves your device — there is no upload, no account, and no tracking.
FAQ
Why is my element sometimes an object and sometimes an array?
Repeated sibling tags collapse into an array, but a tag that appears only once
stays a single value — <catalog><book>A</book><book>B</book></catalog> gives
"book": ["A", "B"], while one <book> gives "book": "A". If your code
expects an array either way, normalize after conversion (wrap non-arrays); the
mapping itself always mirrors what's actually in the document.
What does an empty element like <a/> turn into?
null. An element with no attributes, no children, and no text maps to JSON
null rather than an empty string or empty object, so
<root><a/></root> becomes {"root": {"a": null}}.
Why did "42" come out as a string instead of a number?
Type coercion is off by default because keeping everything as strings is the
safest round-trip. Enable the coercion option to convert integer, float,
true/false and null text into real JSON scalars. Even with coercion on,
leading-zero values like 007 deliberately stay strings so IDs, ZIP codes,
and phone numbers aren't mangled.
Why do I get a "multiple root elements" error?
Well-formed XML must have exactly one root element, and the converter enforces
that — a fragment like <a/><b/> is rejected. Wrap sibling fragments in a
single enclosing element and convert that. Other malformed input (mismatched
tags, unclosed elements) is reported with the byte position where parsing
failed.
Developer & Automation Access
Run it from the terminal
Same engine as this page, headless — via the gizza CLI:
gizza tool xml-to-json '<catalog>
<book id="1"><title>Dune</title><author>Herbert</author></book>
<book id="2"><title>Hyperion</title><author>Simmons</author></book>
</catalog>'New to the CLI? Get gizza →
Open it by URL
Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:
https://gizza.ai/tools/xml-to-json/?xml=%3Ccatalog%3E%0A%20%20%3Cbook%20id%3D%221%22%3E%3Ctitle%3EDune%3C%2Ftitle%3E%3Cauthor%3EHerbert%3C%2Fauthor%3E%3C%2Fbook%3E%0A%20%20%3Cbook%20id%3D%222%22%3E%3Ctitle%3EHyperion%3C%2Ftitle%3E%3Cauthor%3ESimmons%3C%2Fauthor%3E%3C%2Fbook%3E%0A%3C%2Fcatalog%3E&attribute_prefix=%40&text_key=%23text&attributes=true&coerce_types=trueMachine-readable descriptor: tool.json — title + parameters JSON Schema for agents.
