Contact

Tools  /  JSON  /  XML → JSON

XML → JSON

Parse XML with the browser's own parser and represent it as JSON -- customizable attribute prefix and text key, always-array mode, namespace stripping, type coercion, and a structure summary.

What this tool does

Paste or load XML and it is parsed with the browser's own built-in XML parser, then converted to JSON. Using a real parser rather than a hand-written one means malformed XML is caught with an actual parser error, not a converter quietly guessing at broken markup.

The real ambiguity in XML, made configurable

XML has no single obvious JSON shape, because attributes, child elements, and text content all need somewhere to go. An attribute prefix (@ by default) keys every attribute distinctly from child elements, and a text key (#text by default) holds an element's own text when it also has attributes or children — both are editable, for matching whatever convention a project already uses.

Keeping array shape consistent

By default, an element that repeats becomes an array and one that appears only once does not — which means code reading the result has to handle both cases, since the same tag might be an array or a single object depending on how many times it happened to appear in one particular document. Always array forces every repeatable element into an array unconditionally, so downstream code can assume one shape regardless of how many times an element shows up.

Namespaces and types

Strip namespace prefixes removes a leading ns: from element and attribute names when the namespace itself does not matter for the JSON. Ignore attributes drops them entirely when only element content is relevant. Coerce types turns text that looks like a number or true/false into a real JSON number or boolean instead of leaving every value as a string, which is how XML represents everything natively.

Privacy

Parsing and conversion both happen in your browser. Nothing you paste, drop, or load from a file is sent to a server.

Frequently asked questions

Is my data uploaded anywhere?
No. Parsing and conversion both run locally in the browser, using the browser's own built-in XML parser — nothing is sent to a server.
Why would repeated elements need an always-array option?
Without it, an element becomes an array only when it repeats and a plain object when it appears once, so code reading the result has to handle both shapes for the same tag. Always array forces every repeatable element into an array unconditionally, so the shape stays consistent no matter how many times an element actually appears in a given document.
How are XML attributes represented in the JSON?
Each attribute becomes a key prefixed with the configured attribute prefix (@ by default), keeping it visually distinct from child elements in the resulting JSON. The prefix itself can be changed to anything.
Can it detect malformed XML?
Yes — parsing uses the browser's own XML parser, so malformed input produces a genuine parser error rather than a converter silently guessing at broken markup.
What does stripping namespace prefixes do?
It removes a leading namespace prefix such as ns: from element and attribute names in the output, for when the namespace itself carries no meaning worth preserving in the JSON.
Can it convert numeric or boolean-looking text into real JSON types?
Yes, with type coercion turned on — text that looks like a number or the words true or false becomes an actual JSON number or boolean rather than staying a string, which is what every value in XML is natively.
Theme Accent