XML to JSON

Convert XML to JSON, or JSON back to XML. The mapping is the one most libraries use, and it exists because XML has three things JSON does not: attributes, mixed content and repetition. Attributes become keys prefixed with @ so they cannot collide with a child of the same name; an element that has both attributes and its own text keeps that text under #text; and repeated tags become an array, since keeping only the first would silently throw away the rest. Parsing is strict — a mismatched tag gives you an error rather than a quietly repaired structure that does not match your source. Going the other way, the JSON needs exactly one top-level key, because XML allows exactly one root element. Bulk files and folders are supported, and nothing is uploaded.

How XML maps to JSON

XMLJSON
<a>t</a>"a": "t"
<a x="1"/>"a": { "@x": "1" }
<a x="1">t</a>"a": { "@x": "1", "#text": "t" }
<r><i>1</i><i>2</i></r>"r": { "i": ["1", "2"] }
<a/>"a": ""

When to use it

  1. Turn an XML API response into JSON your code can use.
  2. Read an RSS or sitemap feed as structured JSON.
  3. Convert a JSON config into the XML a legacy system expects.
  4. Inspect a SOAP response without reading raw XML.
  5. Check how attributes and repeated elements map before writing a parser.

How to Use

  1. Paste your XML, or drop files in.
  2. Use the swap button to convert JSON back to XML.
  3. Copy or download the result.

Features

  1. XML to JSON and JSON to XML
  2. Attributes prefixed with @, text under #text
  3. Repeated tags become arrays
  4. Strict parsing — real errors, not silent repairs
  5. XML entities escaped, tag names made legal
  6. Bulk folders with ZIP download, all client-side

FAQs

Is my XML uploaded?

No. Conversion happens in your browser.

How are attributes represented?

As keys prefixed with @. So <book id="1"> becomes {"@id": "1"}. The prefix exists so an attribute cannot collide with a child element that happens to share its name — without it, one would overwrite the other.

Why did my single repeated element not become an array?

Because XML has no way to say 'this is a list' — a list of one looks exactly like a single element. Two or more repeated tags become an array; one stays a plain value. If your consumer always expects an array, normalise it after conversion.

What is the #text key for?

An element that has attributes as well as its own text needs somewhere to put the text, because the object is already holding the attributes. An element with only text and no attributes collapses to a plain string instead, which keeps the common case readable.

Why was my JSON rejected when converting to XML?

Most likely it has more than one top-level key, or it is an array. XML allows exactly one root element, so there is no correct way to write two — picking one arbitrarily would lose data, so it is refused with a count instead.

What happens to a key that is not a valid XML tag name?

It is rewritten — spaces become underscores, and a leading digit gets a prefix. XML tag names cannot start with a digit or contain spaces, so emitting them verbatim would produce markup no parser accepts.

Technical Details

XML is read with the browser's own DOMParser in XML mode, which is strict — an unclosed tag or a mismatched one produces a parser error that is surfaced rather than swallowed, unlike HTML mode, which would silently repair the markup and give you a structure your source does not actually have. The mapping to JSON follows the convention most libraries settled on, because XML has three things JSON does not: attributes, mixed content and repetition. Attributes become keys prefixed with @, so they cannot collide with a child element of the same name. An element with children and no attributes collapses to just its text, which keeps the common case readable rather than burying every leaf under a text key. When an element carries both attributes and text, the text moves to #text, since there is nowhere else for it to go. Repeated child tags become an array — the only honest mapping, because keeping the first would silently discard the rest, and XML has no marker distinguishing a list of one from a single element, which is why a one-item list comes back as a plain value. Going the other way, JSON must have exactly one top-level key, because XML allows exactly one root element; more than one is rejected with a count rather than an arbitrary choice. Values are escaped for the five XML entities, and a key that is not a legal tag name — one with spaces, or a leading digit — is rewritten rather than producing markup no parser will accept. Everything runs in your browser.

Data & CSV Tools

Data & CSV Tools

  • Query String to JSON
  • Config to JSON
  • CSV Manipulator
  • Table Format Converter
  • CSV Cleaner
  • CSV Viewer
  • JSON \u21c4 TOON
  • TOML Formatter