XML to JSON Converter Online Free

💻 Developer Tools Free Forever

XML to JSON Converter Online Free

Paste any XML and get clean, valid JSON instantly. Handles attributes, namespaces, arrays, nested elements, and CDATA. Everything runs in your browser. No data sent anywhere.

✔ Attribute support ✔ Namespace handling ✔ CDATA sections ✔ Pretty print or minify ✔ 100% browser-based
Indent
Attributes
Text key
Input XML
Parse error
Output JSON
Choose a sample
About This Tool

XML parsed by the browser’s own DOMParser, then walked into JSON by hand

Rather than writing a custom XML tokenizer, this tool hands your input to DOMParser, the same engine the browser uses to parse XML documents and SVG. That means malformed XML is rejected with the browser’s own real parser error, not a guess from a regex. Once parsed into a DOM tree, the tool walks it recursively and builds a plain JavaScript object, which is then serialized to JSON. Everything happens locally; there is no server call anywhere in the conversion path.

The tree-walking algorithm

Step 1 Parse and check for errors new DOMParser().parseFromString(xml, 'text/xml') builds the tree. Browsers report a parse failure by inserting a <parsererror> element into the resulting document rather than throwing, so the tool explicitly checks for that node and throws its own error using the browser’s message.
Step 2 Walk every node type differently Text nodes (type 3) return their raw string value. CDATA sections (type 4) either return the raw string or, if the CDATA option is enabled, wrap it as { "_cdata": "..." } to mark it as having come from a CDATA block. Comment nodes (type 8) are dropped entirely.
Step 3 Attributes become keys Element attributes are added to the resulting object either prefixed with @ (the default, avoiding collisions with child element names), merged directly as sibling keys, or dropped entirely, depending on the attribute mode setting.
Step 4 Repeated tags become arrays The first time a child tag name is seen it becomes a plain object value. The moment that same tag name appears again as a sibling, the existing value is wrapped in an array and the new one appended, which is how a list of repeated <item> elements becomes a JSON array automatically.
// repeated-sibling-becomes-array logic, from the tool source if (Object.prototype.hasOwnProperty.call(childElements, tagName)) { if (!Array.isArray(childElements[tagName])) { childElements[tagName] = [childElements[tagName]]; } childElements[tagName].push(childVal); } else { childElements[tagName] = opts.forceArrays ? [childVal] : childVal; }

Conversion options and what each one changes

OptionEffect
Attribute modePrefix with @, merge as plain sibling keys, or ignore attributes entirely.
Text keyThe property name used for an element’s own text content when it also has attributes or children (defaults to _text), since a plain string value would otherwise be ambiguous with a child element of the same name.
Parse numbersText content that passes !isNaN(Number(trimmed)) is converted from a string to an actual JSON number.
Parse booleansText content matching the literal strings true or false becomes a real JSON boolean.
Force arraysEvery child element becomes a single-item array on first occurrence too, useful when downstream code expects a consistent array shape regardless of how many times a tag repeats.
Strip namespacesRemoves everything before and including a colon in a tag or attribute name, so soap:Envelope becomes Envelope.
An element with only attributes and no text or children collapses to null. If a tag has no attributes, no child elements, and no non-whitespace text, the walker returns null for it rather than an empty object. This matches common XML-to-JSON library conventions but is worth knowing if your downstream code expects an empty object {} instead, since null and {} behave very differently once you start accessing properties on them.

The reverse direction and other views

JSON back to XML

The swap button reverses the process with its own recursive serializer: keys starting with @ become attributes again, arrays become repeated sibling tags, and the configured text key becomes the element’s text node.

Interactive tree view

A collapsible JSON tree is built as real DOM nodes (not just text), letting you fold and unfold nested objects and arrays to explore deeply nested XML without scrolling through raw text.

Structural stats

Element count, attribute count, and maximum nesting depth are computed by walking the original XML DOM tree, separate from the JSON stats shown for the converted output.

Native browser DOMParser CDATA-aware Namespace stripping Bidirectional (XML to JSON and back)

Parsing standards and tools

Legacy data jobs

Converting a SOAP or legacy XML API response into JSON for use in a modern JavaScript frontend, inspecting an RSS or Atom feed’s structure before writing a parser against it, migrating configuration files from XML to JSON, checking how deeply nested a third party XML export actually is before writing processing code, and turning a downloaded XML sitemap or data export into something easier to query with standard JSON tools.

Common Questions

FAQ: XML to JSON Converter Online Free

Yes, completely free. No account, no signup, no payment required. The tool will stay free forever.

No. All conversion happens inside your browser using JavaScript. Nothing is transmitted to any server. You can safely use it with sensitive or proprietary XML.

You choose. The @prefix option adds an @ before each attribute name so it is easy to distinguish from child elements. The Merge option puts attributes at the same level as children. The Ignore option drops all attributes entirely. Pick whichever matches your downstream usage.

Repeated sibling elements with the same tag name are automatically grouped into a JSON array. So three item tags under a list element become an array of three objects. You can also enable Force arrays to always produce arrays even when there is only one child.

Yes. Click the Swap button to switch the tool into JSON to XML mode. Paste your JSON into the input, click Convert to XML, and download the result as a .xml file.

Yes. By default, namespace prefixes like soap:Body appear as-is in the JSON keys. Enable the Strip namespaces option to remove all prefixes and get cleaner key names. This is useful when working with SOAP APIs or WSDL-based services.

CDATA sections in XML let you include characters like angle brackets without escaping them. With Preserve CDATA enabled, the tool wraps CDATA content in a _cdata key so you know it was a CDATA section. Disable the option to collapse CDATA content directly into a plain string value.

Yes. Click Upload .xml to pick a file from your device, or drag and drop any .xml file directly onto the input area. The file is read locally and never uploaded to a server.

Yes, by default. Text like “42” becomes the JSON number 42, and “true” becomes the JSON boolean true. You can disable either option separately if you need values to stay as strings.

There is no enforced limit. Very large XML files may take a moment to process depending on your browser and device. For files above a few megabytes, the conversion still works but may be slightly slower on older hardware.

Privacy Overview

Cookies let this site remember your preferences and show us which tools people actually use. Full detail sits in our Privacy Policy.