XML to JSON Converter
Convert XML to JSON, with attributes prefixed, text in #text and repeated elements as arrays, optionally always arrays for a stable shape.
Free · No sign-up · Your inputs stay in your browser
Input
Convert XML to JSON
Output
Not well-formed XML
DOMParser is not defined
XML has no single mapping to JSON. Here attributes get a prefix, mixed text goes in #text, and a repeated element becomes an array. That last rule means one entry and two entries give different shapes; 'always use arrays' makes the shape stable for code that consumes it.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
There is no single mapping
XML has attributes, mixed content, namespaces and ordered children; JSON has none of them. Every converter picks a convention, and this one follows the common '@ for attributes, #text for text' style used by xml2js and similar libraries. Order between different child elements is lost.
The one-or-many problem
An element that appears once becomes an object, and twice an array. Code written against a response with one item then breaks on the day there are two. 'Always use arrays' removes that trap at the cost of more brackets. PHP's simplexml_load_string() has the same ambiguity, which is why json_encode(simplexml_load_string($xml)) is a fragile shortcut.