XML to JSON

Turn XML into clean JSON — attributes, repeats and types handled.

Runs in your browser Instant No sign-up
Attribute prefix
Indent
XML
JSON
Reverse

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the XML to JSON converter

  1. Paste, drop or open an XML document in the left pane. It is checked for well-formedness first, and errors show the line and column.
  2. Choose the Attribute prefix: @id, @_id or _id.
  3. Turn Detect numbers & booleans and Always arrays on or off.
  4. Choose the JSON Indent, then Copy or Download the result.

Example

<catalog updated="2026-09-27">
  <book id="bk101">
    <title>Moby Dick</title>
    <price>8.99</price>
    <zip>007</zip>
    <inStock>true</inStock>
  </book>
  <book id="bk102"><title>LOTR</title></book>
</catalog>

becomes

{
  "catalog": {
    "@updated": "2026-09-27",
    "book": [
      {
        "@id": "bk101",
        "title": "Moby Dick",
        "price": 8.99,
        "zip": "007",
        "inStock": true
      },
      {
        "@id": "bk102",
        "title": "LOTR"
      }
    ]
  }
}

The two <book> elements become an array, attributes are prefixed with @, 8.99 and true get their JSON types, and 007 stays a string.

Mapping rules

XML JSON
<a>text</a> "a": "text"
Attribute id="1" "@id": 1 (types on) or "@id": "1"
Repeated <b> elements "b": [ … ]
Text beside child elements "#text": "…"
CDATA section Merged into the text value
XML declaration, processing instructions Dropped

With Always arrays, <a><b>1</b></a> becomes {"a":[{"b":[1]}]} instead of {"a":{"b":1}}. Attributes are never wrapped in arrays.

Choosing an attribute prefix

The prefix keeps attributes from colliding with child elements of the same name. @id is the most readable and matches many JSON conventions. @_id is the default of the popular fast-xml-parser library, so choose it if your code already uses that library. _id avoids the @ sign, which some query languages and templating tools treat specially. Whatever you pick, JSON to XML accepts the same three prefixes, so a document can go back and forth.

With Detect numbers & booleans off, every value is a string: <a><b>1</b></a> becomes {"a":{"b":"1"}}. That is the safer choice when values like part numbers or phone numbers only look numeric.

Limitations

  • Mixed content loses order and inner spacing: <p class="x">Hello <b>world</b> again</p> gives "@class": "x", "b": "world" and "#text": "Helloagain".
  • Comments are not part of the JSON output.
  • Namespaces are kept as part of the name, for example "soap:Envelope", and namespace declarations appear as attributes such as "@xmlns:soap".

Convert back with JSON to XML — the Reverse button on the result opens it with your output — or tidy the source first with the XML Formatter. Explore the converted data in the JSON Viewer or generate types for it with JSON to TypeScript.

Frequently asked questions

Is my XML uploaded?

No. The conversion runs in your browser and nothing is uploaded.

How are attributes represented?

Each attribute becomes a key with a prefix, so id="bk101" becomes "@id": "bk101" by default. Choose @id, @_id or _id under Attribute prefix to match the convention your code expects. Attribute keys come first in each object.

Why is one element an object and another an array?

By default, an element that appears once becomes a single value and an element that repeats becomes an array. Turn on Always arrays to make every element an array, so your code can always loop over it.

Why is 007 still a string?

With Detect numbers & booleans on, 8.99 becomes a number and true becomes a boolean, but values with leading zeros such as ZIP codes or IDs stay strings so no digits are lost. Turn the option off to keep every value as a string.

What happens to text mixed with child elements?

The text is stored under a #text key next to the child elements, with surrounding whitespace trimmed. Mixed content like paragraphs of markup loses its original order — the tool shows a warning when that happens — so XML to JSON works best for data documents rather than prose.

Last updated