How to use this XML to JSON converter
Paste your XML into the box and press “Convert to JSON”. The mapping rules are fixed and documented, so you can predict the output before you run it. An element containing only text becomes that text: <name>Ada</name> becomes "name": "Ada". An element with children becomes an object whose keys are the child tag names. The same tag repeated under one parent becomes an array, in order. Attributes become keys starting with @_, and when an element has both attributes or children and text of its own, the text is kept under the key #text. The root element becomes the single top-level key.
Parsing is done by the XML parser built into your browser — the same strict engine web applications rely on — so malformed XML is rejected with the parser's own message rather than converted into plausible-looking nonsense. That strictness is a feature: if a tag is unclosed or an ampersand is unescaped, you find out here, in a second, instead of inside whatever system was going to consume the data.
Choose pretty output to review the structure, or minified output to hand the JSON straight to an API or a database field. Either way, one honest warning applies to every XML conversion: XML carries no types, so numbers arrive as strings. "36" in the output is text, faithfully copied from between the tags. If your code needs real numbers, convert the specific fields you know are numeric — a blanket guess would corrupt postcodes, phone numbers and IDs that only look numeric.
Example: attributes and repeated tags
The smallest possible document:
becomes:
The sample document shows the fuller rules at work. Its <person id="7"> element carries an attribute, and its two <skill> elements repeat:
The attribute survived as @_id, the repeated tag became an array, and every value is present and accounted for — nothing was dropped or merged on the way.
Why XML needs a documented mapping at all
JSON maps neatly onto the data structures every programming language has: objects, arrays, strings, numbers. XML was designed earlier, for documents, and it shows. It has attributes as well as elements, text can flow around child elements, and the same name can appear at several levels with different meanings. Any XML-to-JSON conversion is therefore a set of decisions, not a mechanical translation — and tools differ in the decisions they make, which is why a feed converted in two places can produce two different shapes. The rules on this page follow the most widely used conventions (the @_ attribute prefix and #text key come from the popular xml-js and fast-xml-parser libraries), so the output will look familiar to most developers and behave predictably in their code.
The single-tag trap, and how to defend against it
The subtlest consequence of the repeated-tag rule is this: a tag that appears twice becomes an array, but the same tag appearing once stays a single value. A catalogue with two phone numbers gives you an array; the day a customer has only one, the same field arrives as a plain string, and code written against the array breaks. This is not a flaw in the conversion — it is the honest reflection of ambiguous source data — but it is worth knowing before you build on converted output. The standard defence is to normalise on your side: after converting, wrap the fields you know are lists in a small “make it an array if it is not one already” step. Forewarned, the trap never springs.
Frequently asked questions
How are XML attributes converted to JSON?
Attributes become keys prefixed with @_ inside the element's object: <person id="7"> converts to "person": { "@_id": "7", ... }. The prefix keeps attributes visibly separate from child elements and prevents collisions when an attribute and a child share a name — a common situation in real XML.
What happens when the same tag appears more than once?
Repeated sibling tags are gathered into an array, in document order. Two <skill> elements under one parent become "skill": ["mathematics", "writing"]. A tag that appears only once stays a single value, so check your data before assuming a field is always an array.
What does the #text key mean?
It holds an element's text when the element also has attributes or child elements. An element containing only text becomes that text directly — <name>Ada</name> becomes "name": "Ada" — but when text shares an element with attributes, the text needs its own key, and #text is the widely used convention for it.
Are numbers in the XML converted to JSON numbers?
No. XML has no numeric type — everything between tags is text — so <age>36</age> becomes "age": "36", a string. Guessing which text fields are really numbers would corrupt values like postcodes and IDs with leading zeros. Convert specific fields in your code after conversion, where you know which ones are numeric.
Why did my XML fail to convert?
The browser's XML parser is strict, and the error message names the problem. The usual causes are an unclosed or mismatched tag, a bare & that should be written &, or text before the root element. Unlike HTML, XML forgives nothing — which is precisely why it works well as a data format.
What happens to comments and the XML declaration?
They are not data, so they are not converted. The <?xml ...?> declaration, comments and processing instructions are skipped, and the JSON describes the element structure only. CDATA sections, by contrast, are content: their text is included like ordinary text.
Can I convert the JSON back to XML?
Mostly. The JSON to XML converter on this site turns the elements back into tags and repeated arrays back into repeated tags. The one loss is attributes: @_ keys become elements named after them, because JSON has no attribute concept to restore them into. Element content round-trips faithfully.
Is my XML uploaded to a server?
No. Parsing uses the XML parser built into your browser, and the conversion runs locally in JavaScript. Feeds, invoices and exported data you paste here are never transmitted or stored anywhere.
How large an XML file can this handle?
There is no limit set by the tool. Documents of several megabytes — large RSS feeds, catalogue exports, sitemap files — convert comfortably on ordinary hardware; the practical limit is your device's memory.