XML to JSON Converter
Free browser-based XML to JSON converter — no sign-up, no upload required. Maps XML attributes to @keys, nests elements, and turns repeated tags into arrays, entirely client-side.
Updated
Frequently Asked Questions
How is an element that has both an attribute and text content converted, like <price currency="USD">19.99</price>?
The attribute forces the element to become a JSON object rather than a plain string, since a plain string value has nowhere to hang the attribute. The text content moves to a #text key alongside the attribute key: {"price": {"@currency": "USD", "#text": "19.99"}}. If the element had no attributes, the same tag would have simplified to a plain string value instead.
What happens to an empty element like <note/> or <note></note>?
Per the XML 1.0 spec, a self-closing tag and an explicitly-closed empty tag are equivalent — there's no way to distinguish them once parsed, so both convert identically. With no attributes and no text or child content, there's nothing to populate the JSON value with, so this typically comes through as an empty string or null rather than an empty object, since there are no attribute or child keys to place inside one.
Are XML comments and processing instructions kept in the JSON output?
No. JSON's grammar (RFC 8259 / ECMA-404) has no comment syntax and no node type analogous to a processing instruction (<?xml-stylesheet type="text/xsl" href="style.xsl"?>), so both are stripped during conversion. Only element structure, attributes, and character data survive the conversion; anything that isn't data in the XML infoset sense is discarded.
Why might converting XML to JSON and back produce a file with different whitespace or attribute order than the original?
Two separate spec gaps compound here. First, XML often contains whitespace-only text nodes between elements purely for pretty-printing indentation, which can surface as stray #text entries unless explicitly stripped. Second, the JSON grammar (ECMA-404) never mandates that object members preserve insertion order — most parsers do in practice, but it isn't a spec guarantee — so attribute order captured as @keys isn't reliably round-trippable either.
If I convert <id>007</id> to JSON, does the value become the number 7 or stay the string "007"?
This is an inherent ambiguity, not a bug in any particular tool. XML has no native numeric or boolean type — per the XML 1.0 spec, every element's content is character data — so an XML-to-JSON conversion always has to make a judgment call about when text should become a JSON number/boolean versus staying a string. That judgment call is genuinely dangerous for values like "007" (a zip or product code, not the number 7) or "1.50" (a price, where casting to a number silently drops the trailing zero as 1.5). The safe default, and the one most conversions favor, is to leave all element and attribute values as JSON strings and let the consuming code decide when and how to cast — that way no information is silently destroyed.
Why do developers convert XML API responses to JSON instead of parsing the XML directly in JavaScript?
Browsers and Node.js have no built-in equivalent of JSON.parse for XML — you'd need DOMParser (browser-only) or an XML library (Node), then hand-write traversal code to pull values out of the DOM tree via getElementsByTagName or XPath. JSON.parse, by contrast, is a single built-in call that hands you plain objects and arrays you can destructure immediately. That gap is exactly why legacy SOAP APIs, RSS/Atom feeds, and sitemap.xml files so often get converted to JSON at the edge of a JavaScript codebase: it's not that JSON is more powerful, it's that the JS tooling for consuming it is already there.
Which came first, XML or JSON, and how does that history explain their design differences?
XML predates JSON by roughly a decade: XML 1.0 became a W3C Recommendation in February 1998, derived from SGML and designed as a document markup language (hence attributes, mixed content, and namespaces). JSON was extracted from JavaScript's object-literal syntax by Douglas Crockford in the early 2000s, first formally specified as RFC 4627 in 2006, then re-specified as ECMA-404 (2013) and its current form, RFC 8259 (2017). JSON's minimalism — four data types, no attributes, no mixed content — reflects its origin as a wire format for passing data structures to and from a running program, not for marking up documents.
Is it true that JSON is basically XML with a lighter syntax?
No — and the @-prefix convention this tool uses for attributes is itself evidence of the gap. That convention (@key for attributes, #text for mixed content) is not part of the JSON specification; it's a widely-used but informal convention, and different XML-to-JSON tools handle the same input differently — some flatten attributes into plain keys, some wrap element content in a $ or _text key, some use the BadgerFish or Parker conventions. JSON has no built-in concept of an attribute at all, so any XML-to-JSON tool is layering its own convention on top of plain JSON objects, and JSON output from one converter won't necessarily match another's for the same XML input.
What happens if two elements from different XML namespaces both happen to be named the same thing, like <a:id> and <b:id>?
Because this converter preserves namespace prefixes literally as part of the key name rather than resolving them to their full namespace URI, "a:id" and "b:id" convert to two distinct JSON keys and won't collide — but only as long as the prefixes themselves differ. If two different parts of a document happen to use the same prefix for different namespace URIs (legal in XML, since prefix bindings are scoped to the element they're declared on), or if a tool downstream re-parses the JSON without namespace context, that prefix-based key no longer reliably identifies which namespace the element actually belonged to. For documents where namespace URIs matter more than prefixes, it's safer to normalize prefixes before conversion.
Embed This Tool
Add a free, live version of this widget to your own website or blog post — it runs entirely in your visitors' browsers, with a credit link back to The Toolbox.
<iframe src="https://getthetoolbox.com/embed/xml-to-json" title="XML to JSON Converter — The Toolbox" width="100%" height="420" style="max-width:480px;border:1px solid #e2e8f0;border-radius:12px" loading="lazy"></iframe>
<p style="font-size:12px;margin:4px 0 0"><a href="https://getthetoolbox.com/converter-tools/xml-to-json?utm_source=embed&utm_medium=widget" target="_blank" rel="noopener">Free XML to JSON Converter</a> by The Toolbox</p>Related Tools
Free Length Converter Online
Convert between meters, feet, inches, miles, and more length units. Free, fast, and works entirely in your browser with no sign-up required.
Free Weight Converter Online
Convert between kg, pounds, ounces, grams, and more weight units. Free, fast, and works entirely in your browser with no sign-up required.
Free Temperature Converter
Convert temperatures between Celsius, Fahrenheit, and Kelvin scales instantly. Free, fast, and works entirely in your browser with no sign-up required.
Free Area Converter Online
Convert between square meters, acres, hectares, and more. Free, fast, and works entirely in your browser with no sign-up required.
About the XML to JSON Converter
XML (W3C's Extensible Markup Language, first published 1998, currently at the 5th edition of the 1.0 spec) and JSON (formalized as ECMA-404 and RFC 8259) solve the same problem — structured, hierarchical data interchange — with genuinely different data models. XML is fundamentally a document format: every node is an element that can carry attributes, ordered child elements, and free text, all interleaved. JSON is a data format built from four structures — object, array, string/number/boolean, and null — with no concept of an attribute or of text sitting alongside child nodes. Converting between them means mapping one model onto the other, and a few of XML's features simply don't have a JSON equivalent.
Attributes. XML attributes live in the element's opening tag: <person id="1" active="true">. Since JSON objects have no attribute concept, this tool maps each attribute to a same-level key prefixed with @:
<person id="1"><name>Ada Lovelace</name></person>
{ "person": { "@id": "1", "name": "Ada Lovelace" } }
Repeated vs. single elements. This is the classic XML-to-JSON ambiguity. If a <skills> element contains three <skill> children, they become a JSON array ("skill": ["Math", "Programming", "History"]). But if it contains only one <skill>, the converter has no schema to consult and can't know whether that element is inherently singular or just happens to occur once right now — so it emits a plain string/object instead of a one-item array. This means the shape of the JSON output can change depending on how many times a sibling tag happens to appear in a given document, which matters if you're writing code against the converted output and expect a consistent array type.
Mixed content. XML permits text and elements to interleave inside the same parent — <p>Hello <b>world</b>!</p> — something JSON objects can't represent directly since object values are either a single string or a nested structure, not an ordered mix of both. This tool maps the text portions to a #text key alongside the child-element keys. That's a reasonable approximation, but it's lossy: JSON's key/value pairs are unordered by the object model, so the interleaving position of text relative to child elements (text before <b>, versus after) isn't fully preserved — you get the pieces, not their original weave.
What doesn't map cleanly. XML namespaces (xmlns:soap="...") and processing instructions (<?xml-stylesheet ...?>) don't have a native JSON representation this converter models. Namespace-prefixed tags come through as literal keys (e.g., "soap:Envelope"), but the prefix-to-URI binding itself isn't tracked separately, and processing instructions are dropped entirely, since JSON has no equivalent node type. XML's DOCTYPE/DTD declarations and entity references (&,  ) are likewise resolved away — you get the resolved character data, not the original markup.
Developers reach for this conversion most often when consuming legacy SOAP/XML APIs from JavaScript front ends, migrating XML config formats into JSON-based tooling, or normalizing XML feeds (RSS, sitemaps, SAML responses) for a JSON-native pipeline. Because the attribute-vs-array ambiguities above mean round-tripping isn't always lossless, treat this as a one-way transform for consumption — not a guarantee that converting back to XML will reproduce the original byte-for-byte.