What Is an XML to JSON Converter?
An XML to JSON converter transforms data written in XML (eXtensible Markup Language) into JSON (JavaScript Object Notation). XML has powered enterprise systems, SOAP web services, RSS feeds, sitemaps, office documents and configuration files for decades. JSON is the lighter, native format of modern web APIs and JavaScript. Converting XML to JSON makes legacy data easy to consume in today's applications.
This converter uses your browser's built-in XML parser, so it validates the XML as it converts and reports the line and column of any syntax error. The mapping rules are predictable: elements become keys, repeated elements become arrays, and attributes are prefixed so they never clash with child element names.
How to Convert XML to JSON
- Paste XML into the input box or drop an .xml, .rss or .svg file.
- Set options. Choose an attribute prefix, indentation, type conversion and array behaviour.
- Read the JSON generated live on the right. Errors in your XML are highlighted.
- Copy or download the JSON output as a .json file.
XML to JSON Mapping Rules
| XML | JSON |
|---|---|
<name>Alice</name> | "name": "Alice" |
<user id="7"> | "user": {"@id": 7} |
Repeated <item> elements | "item": [ ... ] (array) |
<price currency="USD">9.99</price> | "price": {"@currency": "USD", "#text": 9.99} |
<empty/> | "empty": "" |
<![CDATA[ ... ]]> | Plain string content |
Features
- Built-in XML validationMalformed XML is detected with line and column details.
- Attribute supportAttributes are preserved with a configurable prefix (@, _ or none).
- Automatic arraysRepeated sibling elements become JSON arrays, or you can force arrays everywhere for consistent parsing.
- Type conversionNumeric and boolean text becomes real JSON numbers and booleans.
- Handles real-world feedsWorks with RSS, Atom, sitemaps, SOAP responses, KML, GPX and plist files.
- Runs offlineYour XML never leaves your device.
Common Uses
- Consuming SOAP or legacy XML APIs in a JavaScript, Python or mobile app.
- Converting RSS or Atom feeds into JSON for a website widget.
- Migrating XML configuration files to JSON-based systems.
- Inspecting large XML exports in a friendlier format.
XML vs JSON: Why Convert?
| XML | JSON | |
|---|---|---|
| Syntax | Opening and closing tags | Braces, brackets, key/value pairs |
| Verbosity | High, because each tag name is written twice | Compact |
| Data types | Everything is text | Strings, numbers, booleans, null, arrays, objects |
| Attributes | Yes | No (modelled as keys) |
| Native in JavaScript | Needs a DOM parser | JSON.parse |
| Schemas | XSD, DTD | JSON Schema |
JSON is smaller and maps directly to objects and arrays in JavaScript, Python, PHP, Go, Java and virtually every modern language. Converting XML responses to JSON can simplify application code considerably.
Validating XML While You Convert
Well-formed XML must have a single root element, properly nested and closed tags, quoted attribute values and escaped special characters. A bare & must be written as &. If any of these rules is broken, the converter shows the parser's message with the line and column, so you can fix the XML before converting. Common culprits include unescaped ampersands in URLs, mismatched tag case (<Item> vs </item>) and a missing closing tag at the end of a long file.
Worked Example
The XML
<order id="A17" paid="true">
<item qty="2">Coffee</item>
<item qty="1">Bagel</item>
</order>
becomes
{ "order": { "@id": "A17", "@paid": true,
"item": [ { "@qty": 2, "#text": "Coffee" }, { "@qty": 1, "#text": "Bagel" } ] } }
The two <item> elements become an array, attributes gain the @ prefix, and element text with attributes is stored under #text.
Frequently Asked Questions
Can I convert RSS feeds to JSON?
Yes. RSS and Atom feeds are XML documents. Paste the feed source or save it as a file and drop it in. Each <item> or <entry> becomes an element of a JSON array that is easy to loop over in code.
What happens to XML comments and processing instructions?
Comments (<!-- -->) and processing instructions have no JSON equivalent, so they are ignored. All elements, attributes and text are converted.
How are empty elements represented?
An empty element such as <note/> becomes an empty string. If it has attributes, it becomes an object that contains only those attributes.
Can I convert JSON back to XML?
Yes. Use our JSON to XML converter, which follows the same @ attribute and #text conventions for a clean round trip.
How are XML attributes represented in JSON?
By default, attributes become keys prefixed with @, for example "@id": "7". You can switch to an underscore prefix or no prefix.
Why is a single child sometimes not an array?
By default, an element that appears only once becomes an object, and repeated elements become arrays. Enable "Always use arrays" if your code expects arrays regardless of count.
Are XML namespaces supported?
Yes. Prefixed names such as soap:Envelope are kept as-is in the JSON keys, and namespace declarations appear as attributes.
Is my XML uploaded?
No. Parsing and conversion happen entirely in your browser.