Skip to content
Sealpaste

Delete all recent work?

This removes the 0 items saved in this browser. Your settings stay.

Stop saving recent work?

New work won't be saved in this browser. The 0 items already saved can stay or go.

XML to JSON Converter

XML

Paste XML, or

CtrlV paste · Ctrl↵ run now

JSON
Ready
Ln 1, Col 1
Runs in your browser. Nothing you paste is uploaded unless you share it.

Convert XML to JSON: attributes as @name or -name, repeated elements as arrays

Turn XML from an API, a feed or a config file into JSON your code can read. Switch direction to go back.

How to use it

  1. Paste XML on the left, or open a .xml file.
  2. Choose how attributes are marked (@id or -id), and Always arrays if your code needs one shape.
  3. Copy or download the JSON. Use "Swap" to edit the JSON and turn it back into XML.

Examples

Attributes, repeated elements and text

Input
<book id="bk101"><title>XML Guide</title><tag>xml</tag><tag>reference</tag><price currency="USD">44.95</price></book>
Result
{
  "book": {
    "@id": "bk101",
    "title": "XML Guide",
    "tag": [
      "xml",
      "reference"
    ],
    "price": {
      "@currency": "USD",
      "#text": "44.95"
    }
  }
}

The two <tag> elements become an array; the price keeps its attribute, so its text goes under "#text".

Always arrays

Input
<users><user id="1">Ada</user></users>
Result
{
  "users": [
    {
      "user": [
        {
          "@id": "1",
          "#text": "Ada"
        }
      ]
    }
  ]
}

With Always arrays on, a list of one user has the same shape as a list of many.

How XML becomes JSON

The result follows the shape most libraries and tools use:

  • An element becomes a key. Its attributes become keys with a mark: "@id", or "-id" if you choose it.
  • Elements repeated under one parent become an array, in order.
  • An element with only text is that text; an empty element is "". A CDATA section becomes plain text.
  • Text beside attributes or child elements goes under "#text". Spaces and line breaks around text are trimmed.

What JSON can’t hold

XML has only text, so every value is a string: "44.95" stays "44.95", not a number. Comments and processing instructions are dropped, the order between differently named elements is not kept, and text split around child elements is joined. Namespace prefixes stay part of the names, as in "soap:Body".

Entities a DOCTYPE declares are kept as written, not expanded, so an XML bomb or a file-reading external entity (XXE) does nothing.

Questions

Why is one element an array and another not?
An element that appears more than once under its parent becomes an array; one that appears once is a single value. Turn on Always arrays to make every element an array, so the shape doesn’t change when a list has one item.
Why are numbers in quotes?
XML has no numbers or booleans, only text, so the converter keeps every value as the string it was. Converting "44.95" to a number could change it (a price, a zip code with a leading zero).
Is my data uploaded?
No. Everything runs in your browser, so your data stays on your device. Nothing you paste is uploaded unless you share a result, which is locked with your password first. API responses, feeds and config files often hold keys or personal data, and the page warns you if it spots a key.

Related tools