XML to JSON

Converts one XML root to pretty JSON in the browser. Elements become keys, repeated siblings become arrays, and attributes use an @ prefix. This is a converter only: not a schema validator, not XSD, and not lossless for every XML feature.

XML to JSON

Client-side only. XML is not sent to a server. This is a converter, not a schema validator, not XSD, and not lossless for every XML feature.

How to use

  1. Paste XML in the box. Empty or whitespace-only input fails closed. Exactly one root element is required.
  2. Read the pretty JSON (2-space indent) as text and copy it on this device.
  3. Nothing is sent to a server. Refreshing the page clears the form.

Mapping rules

  1. Each element becomes an object key named by its localName (or the full name when there is no namespace prefix).
  2. Repeated sibling tags with the same name become an array.
  3. A text-only element with no attributes becomes a trimmed string.
  4. Attributes become keys prefixed with @, for example @id.
  5. Mixed content is an object with child keys plus a #text field of the concatenated, trimmed character data. A text-only element that has attributes uses #text the same way.
  6. Comments and processing instructions are dropped. CDATA is flattened to text. This is not a lossless dump of every XML feature.
  7. DOCTYPE, DTD, ENTITY, and general entity expansion are rejected. Only the five predefined XML entities and numeric character references are decoded.
  8. Input larger than 100KB, nesting deeper than 32, or more than 5000 element nodes fails closed.

Results

Paste XML to convert to JSON.

Runs in your browser. Nothing is uploaded.

Frequently asked questions

What does this XML to JSON converter do?

It is a browser converter, not a schema validator and not an XSD checker. Paste XML, read pretty JSON (2-space indent) as text, and copy it. The mapping is deterministic but not lossless: comments and processing instructions are dropped, CDATA is flattened to text, and namespaces, mixed content, and other XML features may be simplified.

How are elements, repeats, and text mapped?

The document must have exactly one root element. Each element becomes an object key named by its localName (the part after a namespace prefix), or the full name when there is no prefix. Repeated sibling tags with the same name become an array, in document order. A text-only element with no attributes becomes a trimmed string.

How are attributes and mixed content mapped?

Attributes become keys prefixed with @, for example @id. Mixed content (child elements plus non-whitespace text) becomes an object with the child keys plus a #text field of the concatenated, trimmed character data. A text-only element that also has attributes is an object with those @ keys and #text. Whitespace-only text between child elements is ignored.

Is every XML feature preserved?

No. This is not a lossless round-trip and not a schema or XSD validator. Comments and processing instructions are omitted. CDATA is treated as ordinary text. Namespace prefixes are stripped from element keys. DOCTYPE, DTD, and general entity declarations are rejected rather than expanded.

What input is rejected?

Empty or whitespace-only paste, malformed XML (unclosed or mismatched tags), DOCTYPE / ENTITY / DTD input, general entity references other than the five predefined XML entities and numeric character references, input larger than 100KB, nesting deeper than 32 elements, and more than 5000 element nodes all fail closed with an error. Nothing is sent to a server either way.

Is my XML sent to a server? Do I need an account?

No. Conversion runs in your browser. The paste never leaves the browser. There is no signup, and Tallymill does not save what you paste. Refreshing the page clears the form. Paste is enough; there is no required file upload.