Convert XML to JSON
Attributes, namespaces,
CDATA — handled.
Free XML to JSON converter. Choose how to handle attributes, strip namespaces, force arrays for repeated elements. Uses the browser's native DOMParser — your XML never leaves your device.
Three steps — paste your XML and get clean JSON in seconds.
Paste XML text directly or upload a .xml file. The browser's native DOMParser validates and parses the structure instantly — syntax errors are reported with the line number so you can fix them before converting.
Decide how to handle XML attributes — prefix with @, ignore them, or merge into the object. Strip namespace prefixes for cleaner keys. Choose compact mode to turn text-only nodes into simple string values instead of nested objects.
Click Convert and copy to clipboard or download a .json file. The output is valid JSON ready for any API, JavaScript application, database or data pipeline that consumes JSON.
Why there is no single correct way to convert XML to JSON.
XML and JSON have fundamentally different data models. XML elements can have both attributes and child content simultaneously — a concept that has no direct equivalent in JSON. An element like <user id="1">Alice</user> carries both an attribute (id) and text content (Alice) at the same time. There is no universally agreed mapping for this in JSON.
JSONshift offers two strategies. Compact mode prioritises readability: text-only elements become string values directly ({"name": "Alice"}), and attributes are prefixed with @ to distinguish them from child elements. Verbose mode preserves the full DOM structure — text content lives under a #text key — which is more verbose but fully reversible back to XML.
Namespace prefixes (like soap:Body or ns0:item) make JSON keys awkward and break dot-notation access in JavaScript. The strip option removes the prefix, producing clean keys like Body and item. Keep prefixes when the namespace is semantically meaningful and you need to distinguish between elements from different schemas.
Common workflows where JSON is more practical than XML.
Legacy SOAP and XML-RPC services return XML responses. Converting to JSON allows you to process the data with modern JavaScript, Python or Go tooling without an XML parsing library — and to pass the data to REST API consumers that expect JSON.
RSS and Atom syndication feeds are XML. Converting to JSON lets you consume feed data in a JavaScript front-end, store it in a document database like MongoDB, or process it in a pandas DataFrame without the overhead of an XML parser dependency.
Many legacy applications use XML for configuration (Maven pom.xml, Spring XML, Ant build files). Converting to JSON is often the first step when migrating a project to a modern stack that uses JSON or YAML configuration.
EDI, healthcare (HL7, FHIR), financial (FpML, XBRL) and government data standards use XML. Converting to JSON is a common first step in ETL pipelines that feed modern databases, data lakes or analytics tools that prefer JSON input.
How each setting affects the JSON output structure.
| Option | Values | What it does |
|---|---|---|
| Attributes | @prefix · Ignore · Merge | @prefix adds an @ before each attribute name — e.g. @id, @class — making attributes visually distinct from child elements. Ignore drops all attributes, producing the simplest possible output. Merge puts attributes and child elements in the same object without any prefix — shorter keys but potential name collisions. |
| Output mode | Compact · Verbose | Compact converts text-only nodes to plain string values — {"name":"Alice"} instead of {"name":{"#text":"Alice"}}. Verbose preserves the full DOM structure with explicit #text keys — larger output but fully reversible to XML. |
| Namespaces | Strip · Keep | Strip removes namespace prefixes from element and attribute names (soap:Body → Body). Produces cleaner JSON keys safe for dot-notation access. Keep preserves the prefix — necessary when elements from different namespaces share the same local name. |
| Repeated elements | Always arrays · Mixed | Always arrays wraps every element in an array, even when it appears only once — producing a consistent structure regardless of how many siblings exist. Mixed uses an object for single occurrences and an array for multiples — more compact but can cause type inconsistency if the XML is later extended with additional elements. |
| Formatting | Pretty · Minified | Pretty uses 2-space indentation for human readability. Minified removes all whitespace — smaller payload for API transmission or static assets. |
Other free converters you might need next.
XML parsed by your
own browser. No upload.
The conversion uses the browser's native DOMParser — the same engine that renders every web page you visit. Your XML is parsed locally, the DOM is traversed in JavaScript, and the resulting JSON is built entirely in memory. Nothing leaves your device.
The converter handles real-world XML edge cases: CDATA sections, mixed content (text and child elements in the same node), empty elements, self-closing tags and deeply nested structures — all mapped correctly to their JSON equivalents.
