XML refuses to die quietly. RSS feeds, sitemaps, SOAP remnants, enterprise config files, and half the government data portals on the internet still speak it, while everything you build in 2026 expects JSON. This converter bridges the gap: paste XML, get JSON, with the transformation rules spelled out plainly so you know exactly what happened to attributes, repeated elements, and namespaces. Parsing uses the browser's own DOMParser, the same battle-tested parser your browser uses to read HTML, running entirely on your device.
Why spell out the rules? Because XML-to-JSON is not a neutral format swap. XML has concepts JSON lacks — attributes, mixed content, namespaces, processing instructions — and every converter must decide how to map them. Tools that hide those decisions produce JSON that surprises you later. Here, the mapping is deterministic and documented, which is the difference between output you can build on and output you have to debug.
The Conversion Rules, Exactly
Four rules cover the whole transformation:
- Elements become keys. The element name is the JSON key, its text content becomes the string value.
<channel>News</channel>becomes"channel": "News". - Attributes become @attr keys. Each attribute is stored under its name prefixed with
@.<item id="42">produces"@id": "42"inside the item object. The prefix guarantees an attribute namedtypecan never collide with a child element of the same name. - Repeating elements become arrays. If a parent contains multiple children with the same name, they collapse into one key holding an array. An RSS feed with twelve
<item>elements yields"item": [ ... 12 objects ... ]. A single occurrence stays an object, not a one-element array — a quirk to handle in your code, covered below. - Nesting is preserved. Child elements become nested objects in document order, so a conversion is reversible by eye even when the structures get deep.
A compact worked example. This XML:
<book isbn="978-1-4028-9462-6"><title>The Time Machine</title><author>H. G. Wells</author></book>
converts to JSON with a book object containing "@isbn": "978-1-4028-9462-6", "title": "The Time Machine", and "author": "H. G. Wells". Two books under one parent instead of one would produce a book array of two such objects.
How to Use It (Step by Step)
- Paste your XML into the input area. The tool parses it immediately; there is no button chain to discover.
- If the XML is malformed — an unclosed tag, a mismatched quote — the parser reports the error instead of producing broken output, so you can fix the source first.
- Inspect the JSON result, remembering the four rules above: attributes behind
@prefixes, repeats as arrays. - Copy the result or download it as a .json file for use in your project.
- Round-trip check when precision matters: feed the JSON into a JSON-to-XML converter and compare against your original structure to confirm nothing was lost.
RSS Feeds: The Classic Use Case
RSS is where this conversion earns its keep most often, because every podcast app, news aggregator, and automation script eventually has to eat an RSS feed in a JSON world. A feed's <channel> element holds metadata — title, link, description — while its repeating <item> children carry the episodes or articles. After conversion you get a channel object with an item array, and each item typically carries title, pubDate, link, and for podcasts an enclosure element whose URL and length arrive as @url and @length attributes. That attribute detail is not cosmetic: podcast artwork, audio locations, and file sizes live exclusively in attributes, so any tooling that drops them silently breaks your feed processing.
Sitemaps convert just as cleanly. The <urlset> root holds repeating <url> elements, each with a <loc> child and optional <lastmod>; after conversion, iterating urlset.url as an array gives you every page with its modification date in two lines of code. Enterprise config files, Maven POM snippets, and SOAP response bodies follow the same pattern: repetitive element structures become arrays your JSON tooling already knows how to traverse.
Namespaces and What Happens to Them
XML namespaces qualify element names to avoid collisions between vocabularies — an RSS feed with iTunes podcast extensions, for instance, mixes the base RSS vocabulary with an itunes: prefixed one. The converter keeps namespace prefixes as literal parts of the key: <itunes:duration>1800</itunes:duration> becomes the key "itunes:duration". Nothing is discarded, but nothing is renamed either, so when you consume the JSON you must use the prefixed key as-is.
The practical consequence: after converting a feed with extensions, you will find keys like itunes:author alongside plain author, and they are different fields. Handle both if your code reads feeds from multiple sources, because some publishers use the extension and others do not. XML default namespaces — declared with xmlns without a prefix — do not add a prefix at all, so their elements convert under plain names.
Edge Cases and Honest Limitations
Three structural mismatches between the formats are worth knowing before you write consuming code. First, the single-vs-array problem: one <item> yields an object, two yield an array, so your code should normalize — check whether the value is an array and wrap it if not. Second, all values arrive as strings: XML has no native number or boolean types, so <price>19.99</price> becomes the string "19.99" and available="true" is the string "true"; convert types in your own code when you need real numbers. Third, element text with nested children may combine content in ways that drop the boundary between text and markup — pure-data XML converts cleanly, but documents mixing prose and elements, like XHTML, convert awkwardly and deserve a different tool.
The DOMParser engine is a strength here: it is the same parser rendering pages in your browser, so it handles real-world messy XML — odd encodings within reason, generous whitespace, large documents into the several-megabyte range — with production-grade reliability, and it all runs locally with no upload.
Tips and Best Practices
- Check for the
@prefix first when a field seems missing: the value you want is probably an attribute, not an element. - Normalize arrays in consuming code — treat a lone object as a one-element array so the same logic handles both shapes.
- Convert types explicitly after conversion; XML gives you strings, and sorting prices or comparing counts as strings produces wrong results quietly.
- For feeds with extensions, list the actual keys of a converted item once and record them; mixed-vocabulary feeds differ between publishers.
- Keep the original XML if provenance matters — conversion is lossless for structure but the JSON no longer claims to be XML, and some downstream validators care.