XML to JSON
Convert XML to clean JSON with a real parser and honest conventions.
About this converter
Parses with the browser's genuine XML engine โ malformed input gets a real error naming the problem, never silent garbage โ and emits JSON using the standard conventions: @attributes, arrays for repeated elements, #text for mixed content, typed leaf values.
The mapping, and why converters must choose one
XML and JSON disagree on fundamentals โ XML has attributes, document order and mixed text-and-element content; JSON has none of them โ so every converter invents a mapping, and the honest ones tell you theirs. Here: an attribute becomes an "@name" key; repeated sibling elements become an array; text sharing space with child elements lands in "#text"; and a leaf that looks like a number or boolean converts to one ("42" โ 42), because that's almost always what downstream code wants. The gotcha every consumer of converted XML eventually meets: a list with ONE item converts as an object while two convert as an array, because XML doesn't mark "this repeats" โ code reading the result should handle both shapes. Daily diet: RSS feeds, SOAP responses, sitemaps, legacy API payloads headed into modern tooling. The reverse direction is JSON to XML (same conventions, so the two round-trip), the XML formatter pretty-prints before converting, and the JSON formatter validates after.
Frequently asked questions
How are attributes converted?
As keys prefixed with @ โ <book id="1"> becomes {"@id": "1", โฆ}. It's the widely-used convention, and the JSON-to-XML tool here reads it back, so conversions round-trip.
Why is my list sometimes an object, sometimes an array?
XML doesn't declare 'this element repeats' โ one <item> converts as an object, several as an array. Consuming code should accept both; that's the honest limit of the format gap.
What happens with invalid XML?
A real error from a real parser, naming the issue โ never a shrug and broken output. Fix the input (the XML formatter helps) and convert again.
Are numbers and booleans typed?
Leaf values that parse cleanly convert โ "42" becomes 42, "true" becomes true. Values with leading zeros or mixed content stay strings, deliberately.