Dev · Live
XML to JSON Converter,
and back — instantly.
Paste any XML to get clean, formatted JSON in real-time — or flip the direction and convert JSON back to XML. Attributes become @attributes, repeated siblings become arrays. 100% client-side.
Input XML
1 linesOutput JSON
Enter XML on the left to see JSON here.
XML vs JSON guide
XML vs JSON: what are the differences and when should you use each?
What is XML?
XML (eXtensible Markup Language) is a text-based format for storing and transporting structured data. Defined by the W3C in 1998, it derives from SGML — the same family as HTML — and uses a tag-based syntax where every piece of data is wrapped in named opening and closing tags.
XML supports attributes (metadata on tags), namespaces (to avoid naming conflicts), schemas (XSD for strict validation), comments, and processing instructions. This richness made it the dominant data interchange format of the early web era, widely used in SOAP web services, configuration files (Maven's pom.xml, Android layouts), RSS/Atom feeds, and Microsoft Office document formats (OOXML).
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data interchange format derived from JavaScript object literal syntax. Standardised in ECMA-404 and RFC 8259, it uses a key-value structure with six data types: object, array, string, number, boolean, and null.
JSON was popularised by Douglas Crockford in the early 2000s as a simpler alternative to XML for AJAX applications. It has become the near-universal format for REST APIs, browser storage, configuration files, and NoSQL databases because it maps directly to data structures in every major programming language and is trivially parseable.
Key structural differences
The two formats represent the same underlying data hierarchy in fundamentally different ways:
- Attributes vs. properties: XML elements can carry attributes (
<book id="1">) in addition to child content. JSON has no concept of attributes — all data is a property. This converter maps XML attributes to a special@attributesobject in the JSON output. - Repeated elements vs. arrays: In XML, repeating a sibling tag represents a list (
<item/><item/>). JSON has a native array type ([]). This converter automatically groups sibling elements with the same tag name into a JSON array. - Text content vs. string values: An XML element's text content (
<price>12.99</price>) becomes a JSON string value. Note that JSON distinguishes numbers from strings — all XML text content is currently preserved as strings. - Mixed content: XML allows elements to contain both text and child elements simultaneously. JSON cannot represent this natively. This converter places mixed text content under a
#textkey alongside sibling properties. - Comments and processing instructions: XML supports comments (
<!-- -->) and processing instructions (<?xml ?>). JSON has no comment syntax. Comments are stripped during conversion. - Schema and validation: XML has mature schema languages (XSD, RelaxNG, Schematron). JSON has JSON Schema (draft standard). Both can validate document structure, but XML's tooling is older and more entrenched.
Verbosity and file size
XML is significantly more verbose than JSON. Every value must be wrapped in opening and closing tags, attribute values must be quoted, and the XML declaration adds overhead. For the same data, XML is typically 30–50% larger than JSON. Over millions of API calls, this size difference translates directly to bandwidth costs and parse time.
JSON's minimal syntax (just colons, commas, and brackets) keeps files compact. Minified JSON is even smaller — a 2KB pretty-printed JSON file may compress to 500 bytes when minified.
When to use XML vs JSON
Despite JSON's dominance, XML remains the right choice in specific scenarios:
- Use XML when: you need document-like data with mixed content (text embedded with markup); when your ecosystem uses XML-native tools (XSLT, XPath, XQuery); when interoperating with SOAP web services or older enterprise systems; when your data requires rich metadata via attributes; or when you need namespace support for merging data from multiple sources.
- Use JSON when: building REST APIs consumed by web or mobile clients; storing data in document databases (MongoDB, Firestore); writing configuration files for developer tools; transmitting data in browser applications; or anywhere human readability and tooling simplicity matter.
The conversion challenge: information loss
XML and JSON are not perfectly isomorphic. Some XML features have no JSON equivalent, meaning some information may be lost or approximated during conversion:
- Comments are dropped — JSON has no comment syntax.
- Processing instructions (
<?xml-stylesheet?>) are not preserved. - CDATA sections are collapsed to their text content.
- Namespace declarations (
xmlns:prefix) are currently treated as regular attributes. - Data types: All XML text content is a string in JSON. If you need
<price>12.99</price>to become the number12.99(not the string"12.99"), you need post-processing or a schema-aware converter.