Home / Data tools / XML to JSON converter

XML to JSON Converter

Paste XML and get JSON. Attributes, repeated elements and text are mapped in a predictable way that you can adjust.

How the mapping works

  • Elements become object keys, and the root element is the single top-level key.
  • Attributes become keys that start with a prefix, @ by default, so an id attribute becomes the key "@id".
  • Repeated elements with the same name become an array.
  • Text next to attributes or children goes into a key named #text.
  • Empty elements become null.

Example

<person id="1">
  <name>Ann</name>
  <skills>js</skills>
  <skills>php</skills>
</person>

becomes a person object with "@id": 1, "name": "Ann" and a skills array holding js and php.

Options

Turn on Convert numbers and booleans to get real JSON numbers and true or false values instead of strings. Numbers with leading zeros, such as 007, and very long digit strings stay as text so no information is lost. Change the attribute prefix, or tick Ignore attributes to drop them completely.

Limits

Some XML features have no neat JSON form. Mixed content, where text and elements are interleaved, keeps the text together in #text. The order of differently named siblings is not preserved, because JSON objects group keys. Comments and processing instructions are dropped, and whitespace around text is trimmed.

To convert back, use the JSON to XML converter. For the differences between the formats, read JSON vs XML.

Frequently asked questions

How do I convert XML to JSON?

Paste your XML. The JSON appears in the output box straight away.

What happens to XML attributes?

They become keys with a prefix, @ by default. You can change the prefix or ignore attributes.

How are repeated elements handled?

Elements with the same name inside one parent become a JSON array.

Why does it say my XML is not valid?

The XML is not well formed. Check for unclosed tags, mismatched names and unescaped & characters.