XML to JSON Converter

Convert XML to JSON and back with one documented, stable mapping — attributes, arrays and mixed text included — using DOMParser.

Conversion happens locally in your browser. Your documents never leave your device.

—

How It Works

XML to JSON parses with DOMParser and walks the tree with a hand-written recursive converter; JSON to XML walks the object back out. The mapping is fixed and documented below — the same file always produces the same JSON, and the JSON rebuilds the same XML.

The convention, in one picture
Attributes are collected into an "attr" object on their element; repeated sibling elements with the same name become a JSON array; an element that mixes text with children or attributes keeps its text under "#text"; a childless element is just its text string. Sample mapping:
<book id="b1" lang="en">
  <tag>fiction</tag>
  <tag>classic</tag>
  Price: 12
</book>

=> {
  "book": {
    "attr": { "id": "b1", "lang": "en" },
    "tag": ["fiction", "classic"],
    "#text": "Price: 12"
  }
}
Numbers and booleans stay strings
XML has no data types, so every text value converts to a JSON string as written — "12" never becomes the number 12. That keeps the reverse direction exact (JSON primitives are stringified back) and avoids silently changing values like "007" or "true" that a type-guessing converter would corrupt.
What is dropped, honestly
Comments and processing instructions have no JSON representation in this mapping and do not survive the round trip; CDATA content becomes plain text (which is lossless for the text itself). Namespace prefixes are kept literally, never expanded. The XML declaration is rewritten on export with UTF-8 encoding.

Frequently Asked Questions

Why is there no single 'correct' XML to JSON mapping?

XML has no array type — repeated <item> elements and a single <item> look identical in shape once you lose the count, and XML has no way to say "this list is always a list" without a schema. Every converter must guess, and the guesses differ. That is why several online converters produce different JSON from the same file; this page picks one documented convention and follows it stably in both directions.

Does the tool understand XSD schemas or DTDs?

No. It reads the instance document only — elements, attributes and text as written. It will not consult an XSD to decide whether a single-occurrence element should still be an array, nor resolve external entities. If your consumer needs schema-driven mapping, you will need a converter that loads the schema itself.

What happens with very large XML files?

Everything runs in browser memory, so a file that is tens of megabytes will parse but may feel sluggish when converting, and JSON.stringify doubles the footprint again. For gigabyte feeds, a streaming converter on the server is the honest answer; this tool is built for configuration files, API payloads and document-sized XML.

Can I convert JSON back to XML and get my file again?

Within the documented mapping, yes — this tool's own format round-trips: convert to JSON, change a value, convert back, and attributes, repeated elements and text come out in the same shape you started with. Files produced by other converters with different conventions (for example '@' prefixes or '_' for text) may need manual adjustment.

Is anything uploaded to a server?

No. Parsing and conversion are plain JavaScript plus the browser's DOMParser, running entirely on your device. Your documents — and any credentials inside configuration XML — never leave your machine.