Skip to content

XML to JSON Converter

Paste XML and get JSON back, using the same @attribute-prefix and #text convention as the most common XML-to-JSON libraries — repeated sibling tags automatically become an array, so a list of <book> elements comes out as book: [...] instead of silently overwriting itself down to the last one.

  • Attributes prefixed with @, text content under #text
  • Repeated sibling tags become an array automatically
  • Same structural error checking as the XML Formatter
  • Configurable indent
  • Runs fully client-side

Converter

Parsed locally, nothing uploaded

JSON output

How to convert XML to JSON

  1. 01

    Paste the XML

    A full document or fragment.

  2. 02

    Read the JSON output

    Attributes appear as @name keys; text content of a mixed element appears under #text.

Why attributes get an @ prefix#

XML has two fundamentally different ways to attach data to an element — child elements and attributes — while JSON has only one, a plain object key. Without some convention to tell them apart, <book id="1"><title>X</title></book> and <book><id>1</id><title>X</title></book> would produce identical, ambiguous JSON, losing the distinction entirely. Prefixing attribute keys with @ (the convention used by most XML-to-JSON libraries, including this tool) keeps that distinction visible in the output, so nothing about the original document's shape is silently lost in translation.

The bug this tool avoids: silently losing repeated elements#

A naive attribute-by-attribute converter that just assigns each child to an object key will silently overwrite earlier entries when the same tag name repeats — three <book> elements inside a <catalog> become one, with the first two discarded, unless the converter specifically detects the repetition and switches that key to an array. This tool tracks that automatically: the first <book> becomes a plain object under the book key, and the moment a second one appears, the key becomes an array holding both — this is the single most common correctness bug in hand-rolled XML-to-JSON code, and the exact reason this tool reuses the site's own tested XML tokenizer rather than a second, less careful implementation.

What doesn't survive the conversion#

Comments, processing instructions, the DOCTYPE declaration, and the leading <?xml version="1.0"?> declaration have no JSON equivalent and are dropped entirely — JSON has no concept of a comment or a document-type declaration. If any of that metadata matters for your use case, it needs to be preserved separately; this conversion is strictly about the data the XML actually structures.

Frequently asked questions

Why do attribute names get an @ prefix in the JSON?

Because XML has two different ways to attach data (child elements and attributes) but JSON only has one (object keys). The @ prefix, used by most XML-to-JSON libraries, keeps that distinction visible instead of merging both into indistinguishable keys.

What happens if the same tag appears more than once at the same level?

It becomes a JSON array automatically. This is the most common bug in naive XML-to-JSON converters — silently keeping only the last of several repeated elements — and this tool specifically guards against it.

Do comments and the XML declaration show up in the JSON?

No — they have no JSON equivalent and are dropped. Only the actual data structure the XML represents is converted.

Is my XML sent anywhere?

No. The conversion runs entirely in your browser — nothing is uploaded.

Developers

UUID Generator

Generate cryptographically random UUID v4 or time-ordered UUID v7, in bulk.

Developers

Base64 Encoder & Decoder

Encode and decode Base64 with correct UTF-8 handling, including the URL-safe alphabet.

Developers

ULID Generator

Generate ULIDs — sortable by creation time like UUID v7, but Crockford Base32 instead of hex.