Quick Answer
Paste your XML (or open an .xml file) and the JSON appears instantly. The root element becomes the top-level key, attributes become @keys, elements that repeat become arrays and text next to attributes becomes #text. If the XML is broken, the error message points to the line. Turn on typing to get real numbers and booleans, then copy the JSON or download it as a .json file.
Why Convert XML to JSON?
XML carries a huge amount of the world's data — SOAP and banking APIs, RSS and Atom feeds, sitemaps, e-invoices, KML maps, GPX tracks, SVG graphics, Office files and configuration for Java, .NET and Android. But modern JavaScript apps, Python scripts, NoSQL databases and REST APIs prefer JSON, which is lighter and maps directly onto objects and arrays in code. Converting XML to JSON lets you use that data with familiar tools, without writing a parser.
This XML to JSON converter (XML से JSON) uses your browser's own standards-compliant XML parser, so it handles real-world XML correctly — attributes, namespaces, CDATA and character entities — and shows a clear error when something is broken. It runs entirely on your device: nothing is uploaded.
How to Use It
- Paste XML into the box or press Open file to load an .xml, .rss, .kml, .gpx or .svg file. A sample book catalogue is preloaded.
- Read the status line: it confirms the XML is valid, names the root element and counts the elements — or shows the parser error.
- Choose the attribute prefix (@, _ or none) and the indentation.
- Turn on typing if you want numbers and booleans, and Always use arrays for a consistent structure.
- Copy or download the JSON.
How XML Maps to JSON
XML has elements, attributes and text; JSON has objects, arrays and values. The converter applies these rules:
| XML | JSON |
|---|---|
<name>Asha</name> | "name": "Asha" |
<book id="b1">…</book> | "book": {"@id": "b1", …} |
Two <book> siblings | "book": [{…}, {…}] |
<price currency="INR">250</price> | "price": {"@currency": "INR", "#text": "250"} |
<note/> | "note": "" |
<![CDATA[a < b]]> | "a < b" |
<media:content> | "media:content": … |
The root element is kept as the single top-level key, so <catalog>…</catalog> becomes {"catalog": {…}}. Comments and processing instructions are dropped because JSON has no place for them.
The Array Problem — and the "Always Use Arrays" Option
XML has no array syntax; a list is just the same element repeated. A converter can only tell that something is a list when it sees two or more. That creates a classic bug: a feed with three <item> elements gives "item": [ … ], but the same feed with one item gives "item": { … } — and code that loops over item suddenly breaks.
Ticking Always use arrays fixes this within the document: any tag name that repeats anywhere in it becomes an array everywhere it appears, even where there is only one. For example, if one order has two <line> elements and another has one, both produce arrays. For APIs you call repeatedly, still write code that accepts both an object and an array — a response with a single item in total cannot reveal that the tag is a list.
Choosing an Attribute Prefix
- @ (default): the most common convention, used by many libraries and by our JSON to XML converter — choose it if you might convert back.
- _ (underscore): handy in JavaScript because
book._idworks with dot notation, whereasbook["@id"]needs brackets. - No prefix: the cleanest JSON, but an attribute and a child element with the same name would collide, and the conversion can no longer be reversed exactly.
Strings, Numbers and Booleans
Everything in XML is text, so by default every value is a JSON string — the safest choice, because nothing is changed. Tick Convert numbers and true/false to turn plain numbers such as 250 or -3.5 into JSON numbers and true/false into booleans. Values that only look numeric — PIN codes like 080001, phone numbers with +, amounts with commas and IDs longer than 15 digits — stay strings, so they are never corrupted by rounding or lost zeros. Attribute values are typed the same way.
Clear Errors for Broken XML
XML is strict: a missing closing tag, an unescaped & in text, two root elements, mismatched case (<Item>…</item>) or a stray character before the declaration makes the whole document invalid. Instead of producing half-converted output, the tool shows the parser's message, usually with the line and column, such as "error on line 7 at column 14". Fix that spot and the JSON appears immediately. The most common culprit is a bare ampersand — replace & in text with &.
Common Uses
- Working with SOAP and legacy APIs: turn XML responses into JSON for JavaScript front-ends or quick inspection.
- RSS and Atom feeds: convert a blog or news feed to JSON to display posts in an app.
- Sitemaps: list a site's URLs as JSON for SEO scripts and audits.
- Maps and fitness data: explore KML placemarks or GPX track points as JSON.
- Configuration migration: move XML config files into JSON-based tools.
- Data analysis: load XML exports into Python or JavaScript notebooks via JSON. For a flat table instead, use XML to CSV or XML to Excel.
Example Uses for RSS and Sitemaps
An RSS feed's posts sit under rss → channel → item, so after converting, the list of articles is at json.rss.channel.item, each with title, link and pubDate. A sitemap's pages appear at json.urlset.url, each with loc and often lastmod. Knowing these paths makes it easy to build a news widget, a link checker or an SEO audit script in minutes.
Worked Example
<catalog>
<book id="b1" lang="hi">
<title>गोदान</title>
<price currency="INR">250</price>
</book>
<book id="b2">…</book>
</catalog>
becomes
{"catalog": {"book": [
{"@id": "b1", "@lang": "hi", "title": "गोदान",
"price": {"@currency": "INR", "#text": "250"}},
{"@id": "b2", …}
]}}
The Hindi title is kept exactly, both books form an array, and the price keeps its currency attribute next to its value. With typing on, "#text" would be the number 250.
Using the JSON in Your Code
Once downloaded, the JSON loads like any other file: fetch('data.json').then(r => r.json()) in the browser, JSON.parse(fs.readFileSync('data.json', 'utf8')) in Node.js, or json.load(open('data.json', encoding='utf-8')) in Python. With the @ prefix, read attributes with bracket notation — book["@id"]; with the underscore prefix, book._id works directly. When you need to convert XML automatically inside your own application, popular open-source libraries follow similar conventions, so the structure you see here is a good preview of what your code will receive. Use this page to explore an unfamiliar XML format quickly before writing that code.
Tips for Clean Results
- Turn on "Always use arrays" whenever your code loops over records, so a list with one entry still arrives as an array.
- Keep the @ prefix if you plan to edit the JSON and turn it back into XML.
- Enable typing only when you need maths — strings are the safest for IDs and codes.
- Minify before embedding the JSON in an app or API payload to reduce its size.
- Fix errors at the reported line; one bad character invalidates the whole document.
Works on Any Device
The converter is plain JavaScript using the parser built into every modern browser, so it works on Windows, macOS, Linux, Android and iPhone without installing anything, and keeps working offline once the page has loaded.
Large Files
Files up to 50 MB can be opened. The browser's parser is fast, but very large documents use memory in proportion to their size, so a laptop or desktop is best for big exports. The output box shows the first 200,000 characters to keep the page responsive; Copy and Download always contain the complete JSON. Minified output is noticeably smaller than pretty-printed.
Safe Parsing
The converter uses the browser's built-in DOMParser in XML mode, which does not run scripts, load external files or fetch DTDs, so opening an untrusted XML file here cannot execute code or make network requests. External entity references are not expanded. Your document is only read and turned into text.
Privacy
API responses and exports may contain customer or business data. Everything here happens inside your browser tab — no upload, no server, no storage. Close the tab and the data is gone.
Quick Glossary
- Element: an XML tag and its content.
- Attribute: a name="value" pair inside a start tag.
- CDATA: a section of text that the parser treats literally, used for code or HTML inside XML.
- Namespace: a prefix like
media:that keeps names from different vocabularies apart. - DOMParser: the browser's built-in parser for XML and HTML.
Why Use This Converter?
It is accurate, handles the tricky parts of XML, explains errors clearly, offers a consistent-array mode for reliable code, and keeps everything private — free. Pair it with JSON Formatter to explore the result, or go back with JSON to XML.
XML to JSON Converter — Key Facts
| Input | XML, RSS, KML, GPX, SVG |
|---|---|
| Output | JSON (pretty or minified) |
| Attributes | @name (or _name / name) |
| Repeated tags | Arrays |
| Errors | Line shown for invalid XML |
| Privacy | Runs in your browser |
Frequently Asked Questions
How do I convert XML to JSON?
Paste the XML into the box or open an .xml file. The JSON is produced instantly; copy it or download it as a .json file.
How are XML attributes converted?
Attributes become keys with a prefix — @ by default — so
How are repeated elements handled?
If an element appears more than once under the same parent, its values are collected into an array. Tick 'Always use arrays' to make every repeating tag an array everywhere, even where it appears only once.
What is #text in the output?
When an element has attributes or child elements and also its own text, the text is stored under #text, e.g.
Can it convert numbers to real JSON numbers?
Yes. Tick 'Convert numbers and true/false'. Plain numbers and true/false become JSON types, while values with leading zeros stay strings.
What happens with invalid XML?
The browser's XML parser reports the problem and the tool shows the message with the line, so you can fix the tag or character that breaks the file.
Does it handle CDATA sections and comments?
CDATA content is kept as text. Comments and processing instructions are ignored because JSON has no equivalent.
Can I convert RSS feeds, sitemaps, KML or GPX files?
Yes. They are all XML, so you can open them and get their structure as JSON.
Are namespaces supported?
Yes. Prefixed names such as media:content or xsi:type are kept as written in the JSON keys.
Is my XML uploaded?
No. Parsing happens with your browser's built-in parser; nothing is sent anywhere.
Can I convert JSON back to XML?
Yes, our JSON to XML converter uses the same @ and #text conventions, so the data can round-trip.
Is it free?
Yes, completely free with no sign-up.
XML to JSON in a Click!
Attributes, arrays and clear errors — free and private.
Explore More Prompt Minds Tools
XML to JSON Converter works great alongside our other free tools. Every Prompt Minds tool runs entirely in your browser — no sign-up, no uploads, no watermarks. Browse all free tools.
