Convert XML to JSON Online for Free
Convert XML documents to JSON format. Preserves hierarchy and attributes.
Ad space
Ad space
How to use the XML to JSON
- 1
Open the XML to JSON tool
- 2
Enter your data or upload your file
- 3
Adjust settings if needed
- 4
Get instant results
- 5
Download or copy your output
Frequently asked questions
Is the XML to JSON free?
Yes, our xml to json is 100% free with no limits, no signup, and no watermarks.
Do I need to create an account?
No. You can use the xml to json without any registration. Just open it and start using it.
Is my data safe?
Yes. Any files you upload are automatically deleted after 5 minutes. We never store, share, or access your data.
Does this work on mobile?
Yes. The xml to json is fully responsive and works on phones, tablets, and desktops.
Is there an API for this?
Yes. All our tools are available as API endpoints for developers. Check our API documentation for details.
XML to JSON: Making Tag-Based Documents Readable to Modern Code
XML has been around long enough to power RSS feeds, SOAP APIs, Android and iOS resource files, sitemaps, and a long list of enterprise systems that predate JSON entirely — and every one of those still needs to be read by code that increasingly expects JSON instead of nested tags. An XML-to-JSON converter walks the tag tree and rebuilds it as ordinary JSON: element names become object keys, nested elements become nested objects or arrays, and attributes carry over as their own marked keys rather than vanishing. This tool performs that walk directly in your browser — drop in an XML document, and the equivalent JSON appears instantly, generated by JavaScript running on your own device, with no document ever leaving it to produce that result.
What makes XML awkward to convert by hand isn't the tags themselves so much as the ambiguity around repetition and metadata: a single <item> element and three sibling <item> elements need to become different JSON shapes — one object versus an array of three — and an attribute like id="42" needs to end up somewhere in the resulting JSON without being confused for a child element's own text. Getting those two calls right consistently, across a document with many nesting levels, is the actual job this converter does.
How to Convert XML Into JSON With This Tool
- Paste your XML document into the left panel, or click File to load a .xml file from your device — it's read locally and dropped into that same box, with conversion running the instant valid text lands there.
- Check the status line beneath the input: a green confirmation means the document parsed cleanly, while a red message surfaces the specific parsing error — commonly a mismatched or unclosed tag — instead of failing without explanation.
- Leave Preserve attributes checked to keep every element's attributes in the output as their own keys, or uncheck it to drop attributes entirely and keep only element text and nesting in the resulting JSON.
- Toggle Compact mode to switch the JSON output between an indented, human-readable layout and a single dense line — useful when you're about to paste the result somewhere that doesn't care about formatting.
- Use the swap control between the two panels if you want to try the reverse direction — turning JSON back into XML — on the same page, though that reverse path is a separate, browser-only convenience rather than a billed capability of this particular tool.
- Copy the finished JSON to your clipboard, or download it directly as a .json file.
Nothing here waits on a server round trip: parsing a document, however deeply nested, is arithmetic-adjacent work that a browser's own JavaScript engine finishes essentially instantly.
Why Convert XML to JSON in the First Place
- Consuming an RSS or Atom feed in a modern app. Feed formats are still XML by convention, but most front-end and mobile frameworks are built around JSON data, making a conversion step a near-universal part of any feed reader.
- Talking to a SOAP or legacy XML-based API. Plenty of enterprise systems, especially older ones, only expose XML endpoints; converting a response to JSON right after receiving it lets the rest of an application work with data in the shape it already expects everywhere else.
- Reading Android or iOS resource and configuration files. Mobile app resource formats and various build-tool configuration files are XML at their core, and pulling a specific value out programmatically is often easier once the structure is JSON.
- Processing a sitemap or a structured export. Sitemaps, some CMS exports, and various government or financial data feeds are still published as XML, and a one-time or repeated conversion into JSON simplifies whatever script eventually consumes them.
- Debugging or documenting a document's actual structure. Seeing a deeply nested XML file rendered as indented JSON often makes the real hierarchy easier to read at a glance than scanning through opening and closing tags.
Attributes, Repeated Elements, and Why There's No XXE Risk Here
The API behind this page — a separate, server-side implementation from the one running in your browser — uses a library called fast-xml-parser, and it handles attributes by prefixing each one with @_ in the resulting JSON, so an element written as <user id="42"> produces a key named @_id holding the value "42" alongside whatever the element's own children produce. That prefix is always applied server-side; there's no option to turn attribute preservation off in the API. The on-page JavaScript tool is a genuinely separate implementation built on the browser's native document parser rather than fast-xml-parser, and it makes its own, slightly different choice: attributes there are prefixed with a plain @ rather than @_, and a checkbox lets you drop them from the output entirely if you only care about element text and structure.
Repeated sibling elements are resolved the same conceptual way in both implementations: a single occurrence of a given child element becomes a single JSON object or value, while more than one occurrence of the same element name under the same parent becomes a JSON array of however many there are. This is the detail that trips up a hand-written converter most often, since the correct output shape for one tag name genuinely depends on how many times it happens to appear in that particular document, not on anything declared up front.
On the server side specifically, it's worth being explicit about a security property rather than just asserting it: fast-xml-parser is a regex- and state-machine-based parser, not a DOM or libxml-style parser with DOCTYPE and external-entity resolution built in. It has no mechanism at all for fetching an external DTD, resolving a file:// reference, or expanding an internal entity — which means there's no XXE (XML external entity) vector to guard against here, and no "billion laughs" exponential-expansion attack either, because there's no entity-expansion step in the first place for either kind of payload to exploit. The one resource-exhaustion concern that remains is simply a very large or very deeply nested — but otherwise well-formed — document, which is why the input is capped in size before it ever reaches the parser. A document that's malformed outright, such as one with a tag that opens but never closes, is caught by a validation pass before parsing begins and rejected with a clear error rather than producing a confusing partial result.
How XML Constructs Map to JSON
| XML construct | Resulting JSON |
|---|---|
| An element with only text, e.g. <name>Alice</name> | A string value: "name": "Alice" |
| An attribute, e.g. id="42" | A prefixed key alongside the element's other data |
| A single child element under a parent | A nested JSON object |
| Multiple same-named siblings under one parent | A JSON array, one entry per occurrence |
| An empty element with no text or children | An empty object (or an empty string, in the browser tool) |
| The XML declaration line itself | Not represented — it carries no data to preserve |
Manual Parsing vs. Using This Converter
- Writing a regex to pull values out of tags. It might work for one flat, predictable document, but XML permits nesting, attributes, and repeated elements that a regular expression fundamentally isn't built to track correctly across arbitrary depth.
- A full XML DOM library in your own script. Reliable and standards-compliant, but it means writing your own tree-walk to turn parsed nodes into the JSON shape you actually want, rather than getting that shape directly.
- A code editor's built-in format converter, if it has one. Convenient for a document you already have open, though not every editor includes this, and it's overkill for a single quick conversion you just need to check once.
- This tool's metered API. The endpoint accepts an xml string and returns the parsed structure as JSON directly, with the same attribute-preserving, array-for-repeated-elements behavior described above, useful for a server or script that needs this conversion without a person opening a page at all.
How This Tool Handles Your Data
The conversion you just ran stayed entirely on your device: the XML text was read and transformed by your browser's own parsing code, and no copy of it was sent out anywhere to produce the JSON you're looking at. A separate path exists for automated use — the metered API accepts the same kind of XML as a request parameter and performs an equivalent parse on our server, so if a script or a scheduled job needs this conversion rather than a person clicking through a page, that request body, and therefore the document itself, does leave the caller's machine in a way this browser tool never requires.
Does this XML converter fetch external DTDs or resolve entities from my document?
No. The parser used here has no DOCTYPE or external-entity handling at all, which means there's nothing to disable — it simply never attempts to fetch a referenced DTD or expand an entity reference, closing off the XXE and entity-expansion attack classes by construction rather than by a configuration flag someone has to remember to set.
What happens if my XML is malformed?
A document is validated before parsing begins, and something like a mismatched or unclosed tag is caught at that stage and reported as a clear error rather than being partially parsed into confusing or misleading JSON.
Why do my attribute keys start with an "@" symbol?
That prefix distinguishes an attribute from a genuine child element sharing the same underlying name, since XML allows both an attribute and a child element to exist side by side on one parent. The browser tool on this page uses a plain @ prefix and lets you disable attribute output altogether with a checkbox; the metered API always uses @_ and has no toggle to turn attributes off.
How does the converter know when to make an array instead of a single object?
It counts how many times a given element name appears as a child under the same parent in your specific document. Exactly one occurrence becomes a single object or value; two or more becomes a JSON array holding one entry per occurrence, in document order.
Can this same page also turn JSON back into XML?
The on-page tool includes a swap control that flips the conversion direction, generating XML from JSON as a browser-only convenience. It isn't a separately published, metered API endpoint — it exists purely as part of this page's own JavaScript for quick round-tripping while you're working.
Does the order of elements in my XML survive the conversion?
Yes, for anything that becomes an array: repeated sibling elements are listed in the JSON array in the same order they appear in the document. For a set of distinct, differently named child elements under one parent, JSON object key order is preserved by both the browser's parser and the server-side one, so opening the result in most JSON viewers still reflects the document's original top-to-bottom layout rather than an alphabetized or otherwise reshuffled one.
Related Tools
Once your document is in JSON, JSON to CSV can flatten it into a spreadsheet-friendly grid if the data is essentially tabular underneath its tags. For configuration-shaped XML rather than data feeds, converting through JSON first and then into JSON to YAML often produces a far more readable file than the original markup. If your starting point is actually a CSV export rather than XML, CSV to JSON covers that different starting format with the same JSON destination.
Ad space
Related tools
JSON to CSV
Convert JSON arrays to CSV spreadsheet format. Flatten nested objects, customizable output....
YAML to JSON
Convert YAML configuration files to JSON format. Validates YAML syntax....
JSON Formatter / Beautifier
Format, beautify, and validate JSON data. Tree view, syntax highlighting, and error detection....
Ad space