XML to JSON conversion is one of those chores every developer runs into eventually: a legacy API responds in XML, a config file was written a decade ago, or a partner's SOAP feed refuses to die, and you need that data in JSON so your modern JavaScript, Python, or mobile code can actually use it. This page gives you a free, client-side XML to JSON converter that does the job instantly, without sending a single byte of your document anywhere.
Arb Digital built this tool as part of a growing library of free developer utilities, and like the rest of them it runs entirely in the browser tab you're reading right now. There's no server round-trip, no file upload, no rate limit, and nothing to sign up for. Paste your XML, click convert, and copy the result.
What This XML to JSON Converter Does
This tool reads an XML document and produces an equivalent JSON object using a small set of consistent rules. Element attributes are placed under an "@attributes" key so they never collide with child element names. Plain text content inside an element (once you trim the surrounding whitespace) lands under a "#text" key. When an element has more than one child with the same tag name, siblings, those children are collapsed into a JSON array automatically, so your downstream code can safely loop over them without checking whether it received an object or an array. Self-closing tags such as <note/> become an empty object with no children and no text. Comments and the leading <?xml ...?> declaration are read and then discarded, they carry no data that belongs in JSON, so they simply don't appear in the output.
How to Use It
- Paste your XML. Drop your document into the input box on the left, or leave the sample catalog XML in place to see the tool in action first.
- Choose an indent width. Pick 2 spaces, 4 spaces, or compact (no indentation at all) depending on whether you want the JSON to be readable or as small as possible.
- Click "Convert to JSON." The parser walks your document character by character and builds the JSON structure in a fraction of a second.
- Review the stats. Elements parsed, attributes found, and byte counts for both input and output appear above the output box so you can sanity-check the result at a glance.
- Copy the output. Click "Copy JSON" to send the formatted JSON straight to your clipboard, ready to paste into your code, a config file, or a Postman request body.
How the Conversion Works
Rather than lean on the browser's built-in XML DOM parser and hope its quirks line up with what you expect, this tool ships its own hand-rolled tokenizer written in plain JavaScript. It walks the input string one character at a time, recognizing five distinct constructs as it goes: the <?xml ...?> declaration, XML comments (<!-- ... -->), opening tags with zero or more quoted attributes, self-closing tags that end in />, and closing tags. Whenever it lands on a comment or a declaration, it skips straight past the closing marker and moves on, those two constructs are deliberately excluded from the JSON output because they describe the document itself rather than its data.
Text between tags is buffered as the tokenizer advances, and if that buffered text is nothing but whitespace, spaces, tabs, or newlines sitting between two elements for formatting purposes, it's discarded rather than promoted to a "#text" node. Only text that has real trimmed content survives into the JSON. Along the way, character entities inside both text and attribute values are decoded: & becomes &, < and > become < and >, " and ' become straight quotes, and numeric references like © or © are converted from their decimal or hexadecimal code point back into the actual character. This is the same core entity set defined by the W3C XML 1.0 specification, the official standard that governs how conforming XML documents are structured and interpreted, and it's the authority this tool follows when deciding what counts as valid markup versus plain text.
Once the tokenizer has built a tree of elements, a second pass walks that tree recursively and applies the JSON conventions described above: attributes into "@attributes", trimmed text into "#text", and same-named children grouped into arrays. The root element of your document becomes the single top-level key of the resulting JSON object, so a document rooted at <catalog> produces JSON shaped like {"catalog": {...}}.
XML vs JSON: Two Different Data Models
Part of why XML to JSON conversion is never perfectly mechanical is that XML and JSON were designed around different assumptions. XML is document-shaped: an element can carry attributes, ordered child elements, and interleaved text all at once. JSON has no concept of attributes at all. That mismatch is why this tool needs an explicit convention, @attributes for attributes and #text for character data, rather than one obvious mapping. Other tools use different conventions, like BadgerFish (prefixing attributes with @ and text with $) or the Parker convention (dropping attributes entirely). This converter's naming is a common, readable choice that keeps attribute data recoverable rather than silently discarded, which matters when your XML relies on attributes like id, category, or type to carry meaningful data.
Common Ambiguities: Arrays, Single Objects, and Mixed Content
The trickiest part of any XML to JSON conversion, and the part that trips up hand-written parsers most often, is deciding when a child element should become a JSON array versus a plain object. This tool resolves it the way most production libraries do: if an element has more than one child sharing the same tag name, those children collapse into an array; if there's exactly one, it stays a single object. That rule has one important side effect worth knowing about before you rely on it in production code: if your XML sometimes has one <book> element and sometimes has three, your downstream JSON will sometimes be an object and sometimes be an array under the same key. Code that consumes this JSON should either always call Array.isArray() before iterating, or normalize single results into a one-item array itself.
- Mixed content, elements that contain both text and child elements interleaved, like
<p>Hello <b>world</b>!</p>, is common in document-style XML (HTML-like markup, DocBook, RSS descriptions) but doesn't map cleanly to a JSON tree at all. This converter captures the text portions under#textand the child elements normally, but it does not preserve the original interleaving order between text runs and child tags. If your source XML depends heavily on mixed content, treat this tool as a data-extraction aid rather than a lossless round-trip converter. - Whitespace-only text nodes between elements, the newlines and indentation that make XML readable to humans, are intentionally dropped rather than turned into a series of meaningless
"#text": "\n "entries. This keeps the JSON output focused on actual data. - Empty elements with no attributes, no children, and no text, like the self-closing
<note/>in the sample above, become an empty JSON object{}rather thannullor an empty string, which keeps the structure predictable even when a field happens to be empty.
Real-World Use Cases for XML to JSON Conversion
You'll reach for an XML to JSON converter most often in a handful of recurring situations. RSS and Atom feeds are still published as XML across the web, and pulling a feed's items into a JSON array makes it trivial to render them in a modern JavaScript front end. Legacy SOAP web services, still alive inside enterprises, banks, and government systems, exchange XML envelopes that need to be translated into JSON before a modern REST client can work with them comfortably. Configuration files inherited from older Java, .NET, or Android projects are frequently XML, and converting them to JSON is often the first step in migrating a codebase to a modern config format. And when you're debugging an API that already speaks XML, having a quick way to eyeball the equivalent JSON shape saves real time.
Entity Handling and Namespace Caveats
Entity decoding matters more than it first appears, because a naive find-and-replace approach breaks the moment entities get nested inside attribute values. This tool decodes the five predefined XML entities, &, <, >, ", and ', plus numeric character references in decimal (€) and hexadecimal (€) form, matching the entity rules in the W3C XML specification linked above. One thing this tool deliberately does not attempt is namespace resolution. Namespaced elements like <ns:book> are parsed and passed through as literal tag names rather than resolved against their namespace URIs. For most config files and feeds this is exactly what you want; for namespace-heavy enterprise XML, treat the output as a starting point and double-check any keys that carry a colon.
Arb Digital builds the systems around tools like this one, APIs, data pipelines, and full digital marketing programs. If your XML-to-JSON headache is really a bigger integration project, our services team can help. Or keep browsing our full library of free tools for developers and marketers.
Explore Services All Free ToolsCommon Mistakes to Avoid
- Assuming a key is always an array. Remember that a single matching child stays an object, not a one-item array, code defensively with
Array.isArray(). - Forgetting attributes exist. If a value you expect is missing from the JSON, check whether it was actually an XML attribute rather than a child element, it will be under
@attributes, not a top-level key. - Expecting mixed content to round-trip perfectly. Interleaved text and elements inside the same parent won't preserve their original order in the JSON output.
- Ignoring malformed XML. An unclosed tag or mismatched closing tag will produce a friendly error message in the output box rather than a silent, wrong result, read the error before assuming the converter is broken.
- Piping huge documents through a textarea. This tool is built for typical config files, feeds, and API payloads, not multi-megabyte data dumps; very large documents may be slow to parse in a browser tab.
Related Free Tools From Arb Digital
If you found this XML to JSON converter useful, our other free developer tools cover the rest of the data-wrangling workflow. Going the other direction? Try JSON to XML Converter. Cleaning up markup or scripts before you ship them? Check out the HTML Minifier, the JS Minifier, and the CSS Minifier. Writing documentation? The Markdown to HTML Converter and the HTML Encoder/Decoder round out the set. Browse the full collection on our free tools page.
Frequently Asked Questions
No. The entire conversion happens in JavaScript inside your browser tab. Nothing you paste is uploaded, logged, or transmitted anywhere.
This is the standard XML-to-JSON convention: when an element has more than one child sharing the same tag name, those children collapse into a JSON array. A single occurrence of that tag name stays a plain object rather than a one-item array.
Both are recognized by the tokenizer and skipped entirely. They describe the document itself rather than its data, so they never appear anywhere in the JSON output.
Yes. Every attribute on an element is placed under an "@attributes" object keyed by attribute name, so attribute data is never lost, it's simply kept separate from child elements and text.
Namespaced tags and attributes are parsed and preserved as literal strings (for example "ns:book"), but namespace URIs are not resolved or expanded. For most feeds and config files this is sufficient; for namespace-heavy enterprise XML, treat the output as a starting point.
The parser is wrapped in error handling, so malformed input, an unclosed tag or a mismatched closing tag, produces a clear error message in the output box instead of a crash or a silently wrong result.
This tool runs entirely in your browser β nothing you paste here is ever uploaded or sent to a server.