XML to JSON Converter

Paste an XML document and get JSON for it. Attributes become keys starting with @, the text of an element becomes #text, and elements that repeat become an array. Nothing you paste leaves your browser.

Free Runs in your browser Checked Tuesday, November 10, 2026

A well-formed XML document. A problem is shown with its line and column.

Text such as 12.5 or true becomes a JSON value only when it is written back the same way.

Indentation

Result

JSON — Copy it, or download it as converted.json.
Elements — How many elements were read, the root included.
JSON

This tool runs in your browser. What you enter is not sent to us.

How to use it

  1. Paste the XML into XML. It is checked first, and a problem is shown with its line and column.
  2. Keep Read numbers, true and false as values ticked to get 12.5 as a number, or untick it to keep all text as text.
  3. Choose an Indentation, or No line breaks (minified) for the shortest JSON.
  4. Copy the JSON, or download it as converted.json.

The mapping, rule by rule

The root element becomes the only member of the JSON object, so a root called catalog gives a catalog member. An attribute becomes a member whose name starts with @, such as @id. The text of an element becomes its value when the element has nothing else; when it also has child elements, it becomes the member #text, trimmed of the white space around it.

A child element becomes a member with its name. When the same name occurs more than once, the members become an array in document order. An element with no attributes and no children is null when it is written as a self-closing element (a slash at the end of its tag), and an empty string when it is written with a start tag and an end tag.

  • CDATA sections count as text, exactly as written, so a < character inside one stays a <.
  • Comments and processing instructions are left out, because JSON has no place for them.
  • References such as &amp; and &#65; are read, so the text holds the characters they stand for.

Typed values and what they change

XML has no numbers or booleans of its own: 12.5 in XML is only text. With the typing option on, a text that a JSON number or true or false would give back exactly is read as that value. A text such as 12.50 or 007 stays text, because a number would write it differently.

A list with one item comes back as the item itself, not as an array, because XML cannot tell the two apart. Keep the list in mind when the JSON will be read by a program that expects an array.

Worked example: the default catalog

The default XML is a catalog with two books. The first book has an id attribute, and its title, price and inStock elements become keys. The second book has no inStock element, and its empty price element becomes null.

The JSON has one member, catalog, and its book key is an array of two objects. The count shows 8 elements: the catalog, the two books and their children.

Frequently asked questions

Why does my number come out as text?

Text that a JSON number would not write back exactly stays text: 12.50 keeps its zero, and 007 keeps its leading zeros. Turn off the typing option to keep every value as text.

Why is one element an object and not an array?

An array is made only when the same name occurs twice or more among the children of one element. A single element comes out as its value, which is the usual result for XML.

What happens to comments and processing instructions?

They are left out. JSON has no place for a comment, so the converter reads the data only. Keep the XML if the comments matter to you.

Why does the converter report a line and a column?

The XML must be well-formed before it can be read. The line and column show the first place where the document breaks the XML rules, such as a closing tag that does not match.

Is my XML sent to a server?

No. The conversion runs in your browser. Nothing you paste is sent to our server or stored there.

Sources

Figures and text last checked on Tuesday, November 10, 2026.

We use necessary cookies to run the site. With your consent, Google also uses advertising cookies to show personalised ads. If you reject them, you still see ads, but they are not personalised.