Why convert XML to JSON
XML still powers RSS feeds, sitemaps, SOAP services, invoices, office documents and a lot of enterprise integration. Modern web code, however, works most naturally with JSON. Converting lets you inspect XML data quickly, feed it to JavaScript or store it in document databases.
The converter uses fast-xml-parser with settings chosen to keep information: attributes are kept as keys starting with @, element text next to attributes goes into #text, and elements that repeat become arrays. The XML declaration and processing instructions are dropped because JSON has no place for them.
XML vs JSON at a glance
| Feature | XML | JSON |
|---|---|---|
| Full name | Extensible Markup Language | JavaScript Object Notation |
| Type | Hierarchical markup data | Hierarchical data |
| Introduced | 1998 | Early 2000s (RFC 4627 in 2006) |
| Created by | W3C | Douglas Crockford; now ECMA-404 and RFC 8259 |
| Structure | Nested elements with attributes | Nested objects and arrays |
| Comments | Yes, with <!-- --> | No |
| Data types | Text, unless an XSD schema defines types | String, number, boolean, null, object, array |
| Best for | Enterprise data exchange, feeds and office files | APIs, web apps and app settings |
| Support | Every language; common in enterprise systems | Every programming language |
| MIME type | application/xml | application/json |
How to convert XML to JSON
Step 1: Select the XML file
Drop a .xml file, such as a feed, sitemap or export.
Step 2: Keep JSON as the target
JSON is preselected; CSV and YAML are also available.
Step 3: Convert
The document is parsed and each element becomes a property.
Step 4: Download
Save the pretty-printed .json file.
Mapping rules
Attributes
<item id="7"> becomes { "item": { "@id": 7 } }.
Text with attributes
Element text is stored under #text when attributes are present.
Repeated elements
Two or more siblings with the same name become an array.
Safe numbers
Plain numbers and true or false become JSON values; codes with leading zeros stay strings.
Typical XML to JSON uses
Reading RSS and Atom feeds. Work with feed items as JavaScript objects.
Legacy API migration. Inspect SOAP or XML API responses while moving to JSON.
Sitemap audits. Load URL lists into scripts or spreadsheets.
Config conversion. Move settings from XML files to JSON-based tools.
The single versus repeated element problem
XML does not say whether an element is meant to be a list. If a feed has one item, it becomes an object; with two items, it becomes an array. Code that reads the JSON should therefore handle both shapes, for example by wrapping single values in an array.
This is a limitation of converting XML without a schema, not of this tool, and every generic converter faces it.
What does not carry over
Comments, processing instructions and the XML declaration are removed. Namespace prefixes are kept as part of names, such as media:content, so you can still tell elements apart. Whitespace around text values is trimmed.
Mixed content, where text and elements are interleaved inside the same parent, is simplified: the text parts are merged into #text and their exact positions between child elements are not preserved.
- Kept: elements, attributes, text, namespace prefixes.
- Dropped: comments, declarations, processing instructions.
- Simplified: mixed text and element content.
Tips for XML to JSON
- Check that the XML is well formed; one unclosed tag stops the conversion.
- Normalize single items to arrays in your code before looping over them.
- Large feeds convert fine, but pretty-printed JSON can be bigger than the XML.
- To go back, use the JSON to XML converter, which understands @ and #text keys.
XML to JSON questions
How are attributes represented?
As properties whose names start with @, for example @id or @href.
Why is one element an object and another an array?
Repeated sibling elements become arrays; a single element becomes an object. XML itself does not mark which elements are lists.
Are numbers converted?
Plain numbers and true or false values become JSON numbers and booleans. Values with leading zeros, such as 007, and very long numbers stay strings.
Is the XML declaration kept?
No. The declaration and processing instructions are dropped because JSON cannot represent them.
Does it support namespaces?
Namespace prefixes are kept in property names, for example atom:link.
Is anything uploaded?
No. Parsing happens in your browser.