XML ↔ JSON
Convert XML to JSON and back with DOMParser. Namespaces can be lossy.
Runs in this tab. The file stays here.
This runs in your browser. Nothing is uploaded.
About XML ↔ JSON
Converts XML to JSON and JSON to XML in your browser with DOMParser, with honest limits around namespaces and complex documents.
XML to JSON is another rainy-afternoon script, usually written just badly enough to drop attributes, or outsourced to a converter that stores your SOAP envelope. I wanted the boring version in the tab: parse with DOMParser, walk the tree, emit indented JSON going one way, and build element trees going the other. Paste, pick a direction, copy. No upload, no account, no 'we'll email you the result'. The parser error panel is the browser's own message trimmed, not a vague 'invalid' from a black box.
Namespaces are where honest tools admit limits. DOMParser gives me a tree I can serialize; prefix games, default namespaces, and documents where the same local name means different things in different scopes may not round-trip the way a schema-aware toolchain would. Attributes become keys prefixed with @ in the JSON view. Text nodes and child elements merge with the rules you see in the output, not with twenty years of XML infoset pedantry. If you need guaranteed namespace fidelity, use the stack that already validates against your XSD. Mixed content with interleaved text and tags will flatten into the JSON shape this page uses, which is readable but not universal. Huge documents load whole into memory like any in-tab parser, so split multi-megabyte logs before you paste them.
JSON back to XML wraps a root element around your object unless the JSON already has a single top-level key, in which case that key becomes the root tag. Arrays become repeated elements. That's enough for config snippets, simple feeds, and test fixtures. It is not a general purpose XML editor, and it won't preserve processing instructions, comments, or CDATA semantics you didn't express in the JSON shape. Eyeball a round trip on a small sample before you batch-convert production XML you cannot afford to mangle. When JSON to XML fails, the error usually means the object shape cannot become a sane tag tree, not that your XML parser is broken.
How to use XML ↔ JSON
- 1Paste XML or JSON into the panel.
- 2Choose XML to JSON or JSON to XML.
- 3Copy the result, or read the parser error if the input was malformed.
What it won't do
- DOMParser tree rules; complex namespaces and mixed content may not round-trip.
- No XSD or DTD validation, no XPath, no streaming for huge documents.
Common questions
Why might XML namespaces be lossy here?
Because this path uses DOMParser and a simple tree walk, not a full XSD pipeline. Prefixes may normalize, default namespaces may not survive a round trip the way libxml would guarantee, and mixed-namespace documents can flatten oddly. Inspect the output before you trust it in production.
How are XML attributes represented in JSON?
As keys starting with @ on the object for that element, alongside child element keys. Text content lands in a #text field when elements and text mix. It is a convention, not a standard; treat it as this page's shape, not a universal XML-to-JSON spec.
Does this page validate against an XSD or DTD?
No. It checks well-formedness via the parser. Invalid XML shows a parsererror message. Schema validation belongs in CI or in the service that consumes the document.
Related tools
Why this one doesn't upload your file
There is no server to upload to. This page is a static file, and the work happens in your browser using the same graphics and WebAssembly code that renders every other site you visit. Your file is read from disk into memory, processed, and handed back as a download. Once the page has loaded you can disconnect from the network entirely and it keeps working. The longer explanation