XML to JSON Converter
Convert XML data or files to JSON format instantly in your browser. Supports custom indentation and handles nested structures.
Select XML file
or drag and drop here
Convert XML data or files to JSON format instantly in your browser. Supports custom indentation and handles nested structures.
or drag and drop here
XML and JSON are both data interchange formats but come from different eras of the web. XML, standardized in 1998, was designed as a self-describing markup format with attributes, namespaces, and schema validation. JSON emerged in the early 2000s as a lighter-weight format better suited to JavaScript runtimes and modern APIs. Most new web APIs speak JSON; many older systems — SOAP services, RSS feeds, configuration files, enterprise integrations — still produce XML. Converting between them is one of the most common interop tasks in modern development.
The conversion is not perfectly lossless because the two formats have different expressive power. XML has attributes (which JSON does not natively), distinguishes between text content and element names, and supports mixed content (elements containing both text and child elements). JSON's straightforward object/array model cannot directly represent these features, so converters apply conventions: attributes become @-prefixed keys, text content becomes a #text key, and so on.
This converter parses XML using the browser's built-in DOMParser and walks the resulting DOM tree to produce JSON. Elements with the same tag name as siblings are collected into arrays; attributes go into special keys; namespaces and processing instructions are preserved when present. The result is human-readable JSON that round-trips reasonably back to XML.
Most modern application code is more comfortable with JSON. JavaScript parses JSON natively, Python's json module is in the standard library, and virtually every other language has equivalent first-class JSON support. XML processing requires importing additional libraries and writing more boilerplate. Converting incoming XML to JSON before processing is often the quickest path from external XML feed to internal data structure.
Tooling also leans JSON. JSON beautifiers, validators, schema validators, query languages (jq, JSONPath), and viewers are abundant; the XML equivalents are fewer and frequently older. Working in JSON unlocks a richer ecosystem of tools.
Paste XML, get JSON.
DOMParser produces an XML DOM identical to what the browser uses for XHTML pages. The converter walks this DOM recursively. For each element it creates a JSON object: attributes become keys prefixed with @ (e.g., @id, @class); the element's child elements are recursed into the same structure; text content, when present alongside children, lives under a #text key.
Repeated child elements with the same tag name are collected into a JSON array. A single child of a given name appears as an object value; multiple children appear as an array of objects. This convention works well in practice but means the JSON shape depends on whether elements appear once or multiple times — a known imperfection of XML-to-JSON mapping.
Namespaces are preserved as part of element names (prefix:localName). Processing instructions and CDATA sections are converted to text content. XML declarations and DOCTYPEs are stripped from the JSON output but do not affect the data.