XML to JSON converter
Convert XML to JSON in your browser, with attributes preserved and parse errors reported by line. Nothing is uploaded.
About this converter
XML is what older enterprise systems, SOAP services, RSS feeds and most government data portals still speak. JSON is what everything you are writing today expects. Converting between them is a routine task with one genuinely hard problem: XML carries information that JSON has no direct place for.
Attributes are the clearest case. An element like a price tag with a currency attribute has two pieces of information, and a naive conversion throws one away. This converter keeps attributes, prefixing them with @_ so they sit alongside the element content instead of colliding with child elements of the same name. You can switch that off if your XML uses attributes purely decoratively.
The second problem is repetition. XML expresses a list by repeating an element; JSON expresses one with array brackets. That means an element appearing twice becomes an array, and an element appearing once becomes a plain object - so a list containing a single item has a genuinely different shape from one containing two. This trips up more integrations than anything else in XML handling, so the converter flags it on every conversion. If you are writing code against the output, handle both shapes.
Malformed XML is reported with a line and column number rather than a generic failure, which matters because the usual reason a conversion fails is an unescaped ampersand somewhere in the middle of a large file.
Optional value parsing turns numeric strings into numbers and true/false into booleans. Leave it off if your XML contains identifiers with leading zeros or version strings where 1.10 must not become 1.1.
The conversion runs in your browser, which is worth knowing if the XML came out of a system holding real records.
Frequently asked questions
- Why is a single-item list an object rather than an array?
- XML has no way to say "this is a list of one". The converter cannot tell the difference, so code reading the output should accept both an object and an array for any repeatable element.
- What does the @_ prefix mean?
- It marks an XML attribute, so attributes and child elements sharing a name do not overwrite each other. Turn attributes off if you do not need them.
- Are namespaces preserved?
- Prefixed element names are kept as they appear, so ns:element stays ns:element. The namespace URI declarations are kept as ordinary attributes.