Handitab

XML to JSON

Convert XML to JSON, keeping attributes as keys with an @ prefix and turning repeated child elements into arrays automatically.

About XML to JSON

XML to JSON conversion has no single standard, so each tool picks a convention. This one parses the document with the browser's DOMParser, stores attributes as keys prefixed with @, stores text that sits beside attributes under #text, and turns repeated sibling elements into an array. Elements with only text become strings. Comments and text mixed between child elements are not preserved, and all values stay strings.

How to use XML to JSON

  1. Type or paste into the "XML" box, or press "Use example" to try it with sample data.
  2. The result appears below and updates as you type.
  3. Copy the result with the copy button, or download it as a file where that is offered.

Questions about XML to JSON

Why is a single child element an object while several become an array?

The converter only creates an array when it sees the same tag name more than once under one parent. A list with one item therefore comes out as a single value, so code reading the result should handle both shapes.

Runs in your browser. Page last updated .

More encoding and data tools

All 28 encoding and data tools