XML to JSON Converter
Convert XML documents into clean, structured JSON. Preserves element hierarchy, attributes, and text content — ready for modern APIs and applications.
How to Convert XML to JSON
- Paste your XML into the input field. The tool comes pre-loaded with sample XML — a users collection with attributes and nested elements — so you can test the conversion immediately.
- Choose your indentation preference. Check "Pretty-print output" for human-readable JSON with line breaks and indentation. Toggle the
@attribute prefix to clearly distinguish between XML attributes and child elements in the resulting JSON. - Click "Convert to JSON". The browser's native DOMParser reads your XML, then the converter recursively walks the document tree, building a JSON object that preserves the original structure, attributes, and text content.
- Copy or download the resulting JSON for your application, API integration, or data analysis pipeline.
Supported XML Features
- Attributes with
@prefix. XML attributes are converted to JSON properties. With the prefix option enabled,<item type="book">produces"@type": "book", clearly separating metadata from structural data. - Text nodes preserved as
#text. When an element mixes child elements with inline text — like<p>Hello <b>world</b></p>— the text portion is stored under the#textkey so no content is lost. - CDATA sections.
<![CDATA[...]]>blocks are extracted as plain text. No special escaping is needed — the content arrives as-is in the JSON value. - Self-closing tags.
<br/>and<img src="..."/>are handled correctly, producing objects that may be empty or carry only attributes. - Repeated elements become arrays. Multiple sibling elements with the same tag name — like several
<item>entries — are automatically collected into a JSON array for iteration. - XML namespaces. Namespaced tags like
<ns:element>preserve their full qualified name as the JSON key, so namespace information is not silently dropped.
When to Use XML to JSON
- Wrangling SOAP API responses. SOAP web services return deeply nested XML envelopes. Convert those responses to JSON for immediate consumption in your JavaScript frontend or Node.js backend without pulling in a heavyweight XML library.
- Parsing RSS and Atom feeds. Blog feeds, podcast syndication data, and news aggregators speak XML. Convert feed data to JSON and you can process it with a single
JSON.parse()call instead of wrestling with DOM traversal. - Analyzing sitemap.xml files. SEO audits often involve checking hundreds of URLs in a sitemap. Converting the XML sitemap to JSON lets you pipe it directly into a script or spreadsheet for filtering, sorting, and reporting.
- Bridging legacy enterprise integration. Many ERP and CRM systems produce XML exports. Converting those to JSON unlocks the data for modern analytics platforms, data warehouses, and cloud services that expect JSON inputs.
- Migrating configuration files. Older frameworks use XML for configuration (
web.config,pom.xml,struts-config.xml). Convert these to JSON as a first step toward a modern configuration management system or infrastructure-as-code pipeline.
Format Gotchas
- Mixed content is tricky. XML allows elements like
<para>Click <link href="/">here</link> for help</para>, where text and child elements are interleaved. The converter stores standalone text segments in#textkeys, but the original sequence is lost — the text before, between, and after child elements gets collapsed. - Attribute vs. element naming conflicts. If your XML has an attribute and a child element with the same name — e.g.,
<book id="1"><id>wrong</id></book>— the attribute and element collide in the JSON object. The last one processed wins. Use the@prefix to avoid collisions. - Namespace prefixes survive as-is. The converter does not resolve namespace URIs to their prefixes —
<xsl:template>stays as"xsl:template"in the JSON key. This preserves information but means you'll need to handle colons in your JavaScript property access (use bracket notation:obj["xsl:template"]). - XML declaration encoding is ignored. The
<?xml version="1.0" encoding="ISO-8859-1"?>declaration is stripped. The converter assumes your input is UTF-8 or compatible. For non-UTF-8 encoded XML, pre-convert the file to UTF-8 before pasting. - Very large files may slow your tab. The DOMParser builds an in-memory document tree. XML files above 10 MB with deep nesting can consume significant browser memory and cause a noticeable pause during conversion. For massive enterprise XML dumps, consider splitting the file first.
FAQ
Is my data secure?
Yes. All XML parsing and JSON generation runs entirely in your browser. No data is uploaded to any server, transmitted over the network, or stored anywhere. Open your browser's Developer Tools (F12), go to the Network tab, and click Convert — you'll see exactly zero outbound requests.
What's the maximum XML file size?
The browser's DOMParser handles files up to approximately 10-50 MB depending on your device's available memory and the XML's structural complexity. Deeply nested documents with hundreds of thousands of elements consume more memory than flat ones of the same byte size. If your file exceeds this range, consider splitting it into smaller chunks or using a dedicated XML streaming parser offline.
Can I convert JSON back to XML?
Yes — our JSON to XML converter handles the reverse direction. Note that the round-trip is not always lossless: XML attributes (converted with the @ prefix) may not map back identically, and mixed content sequences cannot be reconstructed exactly.
Are XML attributes preserved in the output?
Yes. By default, attribute names are included as-is. Enable the "Prefix attributes with @" checkbox to visually distinguish them — <book genre="fiction"> becomes "@genre": "fiction". Without the prefix, the attribute key is just "genre" with no visual distinction from child elements.
How does the converter handle XML namespaces?
Namespace prefixes are preserved in the tag name as JSON keys. <dc:title> becomes the key "dc:title". The namespace URI itself is not resolved or included separately. If you rely on namespace resolution, you'll need to post-process the JSON to map prefixes to their full URIs.