json:yaml

XML to JSON converter

Convert XML to JSON: elements become keys, repeated tags become arrays, and attributes are kept with an @ prefix. Parsed by your browser's own XML engine.

XML
JSON

      
Paste XML to convert.

Conversion happens in this browser tab. Nothing is uploaded, logged, or stored.

The mapping

The document is parsed with the browser's own XML parser, then walked into a plain JSON structure:

  • Each element becomes a key named after its tag.
  • Elements with children become objects; elements with only text become scalars.
  • Repeated sibling tags collapse into an array.
  • Attributes are kept, prefixed with @, so <user id="7"> yields "@id": "7".
  • An element with both attributes and text puts the text under #text, because the attributes need somewhere to live alongside it. <user id="7">Ada</user> becomes {"@id": "7", "#text": "Ada"}.
  • Empty elements become null.
  • Numeric and boolean text is converted; everything else stays a string.

The one-element array problem

Telling a one-element list from a single value is the hard part of XML to JSON, and no converter solves it without a schema.

<items>
  <item>A</item>
  <item>B</item>
</items>
<!-- becomes: { "item": ["A", "B"] } -->

<items>
  <item>A</item>
</items>
<!-- becomes: { "item": "A" }  — a scalar, not an array -->

The same XML structure produces a different JSON shape depending on how many children happen to be present. Code that does data.items.item.map(...) works on the first document and throws on the second.

Defend against it in the consumer, not the converter:

const items = [].concat(data.items?.item ?? []);

What is dropped

XML featureResult
CommentsDropped
Processing instructionsDropped
Namespace prefixesKept as part of the key name, e.g. ns:tag
CDATA sectionsUnwrapped to their text content
Mixed content (text beside elements)The loose text is lost
Element order across different tagsNot preserved as an explicit sequence

To go back, use JSON to XML. If the result is destined for a config file rather than an API, JSON to YAML is usually the more readable target.

Mixed content is the significant one. Markup like <p>Hello <b>there</b></p> has no natural JSON equivalent. For document-shaped XML, JSON is the wrong target format.

Your document stays local

Most XML that needs converting comes from a system somebody would rather not touch — a legacy feed, a bank statement export, a health or insurance interchange file. The formats are old and the contents are usually regulated.

This tool cannot leak them. Parsing uses your browser's own XML engine, the result is assembled in the same tab, and no request carrying your document is ever made.

Questions people ask

How are attributes represented?
As keys prefixed with @. An element written as <user id="7"> produces a key called @id with the value "7".
Why is a list with one item not an array?
Because XML gives the parser no way to tell. Two repeated tags clearly form an array; one tag is indistinguishable from a single value. Defend against it in your consuming code by coercing to an array.
What happens to comments and processing instructions?
They are dropped. JSON has no equivalent for either.
Are namespaces supported?
Prefixes are kept as part of the key name, so ns:tag stays ns:tag. Namespace URI declarations are not resolved.
Why did some text disappear?
Mixed content — loose text sitting beside child elements — has no JSON equivalent and is lost. For document-shaped XML, JSON is the wrong target format.