XML to JSON
Convert XML documents to JSON format β paste your XML, click Convert, and copy the result.
What is XML?
XML (eXtensible Markup Language) is a text-based format for representing structured data using nested tags. Developed by the W3C and published in 1998, XML was the dominant data exchange format for web services and enterprise systems throughout the 2000s. While JSON has largely replaced XML for new web APIs, XML remains widely used in: Microsoft Office documents (docx, xlsx, pptx are ZIP archives containing XML), RSS and Atom feeds, SOAP web services, SVG graphics, Android layout files, Maven build configurations, and many enterprise systems (SAP, Oracle, healthcare HL7 formats).
<!-- Example XML -->
<users>
<user id="1">
<name>Alice</name>
<age>30</age>
</user>
</users>What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based format that uses keyβvalue pairs and ordered lists. Derived from JavaScript object syntax and formally specified in RFC 8259, JSON is now the standard format for REST APIs, web application configuration, and data interchange between modern services. JSON is more compact, easier to read, and faster to parse than XML for most use cases.
// Equivalent JSON
{
"users": {
"user": [
{ "@id": "1", "name": "Alice", "age": "30" }
]
}
}XML vs. JSON: key differences
| Feature | XML | JSON |
|---|---|---|
| Syntax | Tag-based: <key>value</key> | Key-value: "key": "value" |
| Attributes | Supported natively | No direct equivalent (use @ prefix convention) |
| Comments | <!-- supported --> | Not supported |
| Arrays | Repeated sibling tags (implicit) | Explicit array syntax [ ] |
| Data types | All values are text strings | String, number, boolean, null, array, object |
| Namespaces | Supported (xmlns) | Not supported |
| Verbosity | High β opening and closing tags for every field | Low β compact syntax |
| Best for | Documents, enterprise, SOAP, SVG | REST APIs, config files, modern web |
How this converter handles XML structures
XML has features that have no direct JSON equivalent. This converter uses the following mapping conventions:
XML element β JSON key with its text as the value
XML attribute β JSON key prefixed with "@"
Repeated tags β JSON array (auto-detected)
Nested elements β Nested JSON objects
Example:
<book id="42">
<title>Dune</title>
<author>Herbert</author>
<author>Anderson</author>
</book>
β {
"book": {
"@id": "42",
"title": "Dune",
"author": ["Herbert", "Anderson"] β array, auto-detected
}
}Common use cases
Tips for XML-to-JSON conversions
- Attributes become @-prefixed keys. An XML attribute like
id="1"becomes"@id": "1"in the JSON output. This is a common convention; if your downstream system expects a different attribute format, rename the keys after converting. - All XML values are strings. XML has no native number or boolean type β everything is text. After conversion, a JSON field that looks like a number is still a string:
"age": "30", not"age": 30. If your application needs typed values, cast them after conversion. - XML namespaces are not preserved. Namespaced tags like
<ns:user>are converted using the full tag name including the prefix. Namespace declarations (xmlns:ns="...") appear as @-prefixed attributes. For complex SOAP envelopes with multiple namespaces, manual cleanup is typically needed. - Validate your XML before converting. XML is strict: unclosed tags, missing quotes around attributes, or illegal characters cause parse errors. Use a validator or linter to confirm your XML is well-formed before pasting it here, particularly with hand-written or legacy XML.
Frequently asked questions
What does this tool do?
It parses XML and converts it into equivalent JSON, making the data easier to use in JavaScript and modern APIs.
Is the conversion done locally?
Yes. Your XML is converted in the browser, so nothing is sent to a server.
How are XML attributes represented in JSON?
Attributes are typically mapped to special keys (often prefixed) alongside element content, since JSON has no direct attribute concept.
Why convert XML to JSON?
JSON is lighter, natively supported in JavaScript, and easier to work with in most modern web and API contexts than verbose XML.
Parses the XML structure and converts elements to JSON objects. Attributes are prefixed with @. Repeated sibling elements become arrays automatically.