Free No sign-up Client-side

XML to JSON Converter

Drop in an XML document and get a clean JSON object back — element names become keys, nested tags become nested objects, all without a single byte leaving your browser.

InputJSON
Output
Input: 0 lines · 0 charsOutput: 0 lines · 0 chars Processed locally in your browser

Turning a markup tree into a data object

XML and JSON both describe hierarchical data, but they reach for different shapes to do it. XML wraps everything in opening and closing tags; JSON leans on braces, brackets and key/value pairs. This converter walks the XML tree and rebuilds it as the equivalent JavaScript object, so a <book> element becomes a book property and its children become nested properties of that object.

The parsing is handled by xml2js via its parseStringPromise function, configured with explicitArray: false. That single option matters a lot: instead of wrapping every value in a one-element array (xml2js's default), it only creates arrays where an element genuinely repeats. The result reads the way you'd hand-write the JSON yourself.

If the XML can't be parsed — an unclosed tag, a stray ampersand, two root elements — you get an Invalid XML format message rather than half-baked output. Everything runs client-side, so API responses and config files never touch a server.

Converting XML to JSON in four moves

  1. 1

    Paste or upload XML

    Drop your XML into the left pane, or load an .xml file from disk. The sample button gives you something to experiment with.

  2. 2

    Watch JSON appear

    Conversion runs as you type, so the JSON object materialises in the right pane without clicking anything.

  3. 3

    Read or fix

    Scan the keys and nesting. If the input isn't well-formed, the error banner points you at the problem before you trust the output.

  4. 4

    Take it with you

    Copy the JSON to your clipboard or download it as a .json file ready to drop into code.

What this saves you

Feed legacy XML to modern code

Most JavaScript and TypeScript stacks speak JSON natively. Convert once and skip writing a bespoke XML parser.

Inspect SOAP and RSS quickly

Turn a verbose API envelope into a JSON object you can drill into with a quick console.log.

Sensible array handling

Because explicitArray is off, repeated elements become arrays and single elements stay objects — no array-of-one noise.

Zero data exposure

Parsing happens locally, so internal schemas and payloads never leave the machine you're working on.

A small document, converted

An XML record on the left, the JSON xml2js produces on the right.

Catalog entry → JSON
<book id="b12">
  <title>Dune</title>
  <author>Frank Herbert</author>
  <year>1965</year>
</book>
{
  "book": {
    "$": {
      "id": "b12"
    },
    "title": "Dune",
    "author": "Frank Herbert",
    "year": "1965"
  }
}

How attributes and text content map across

XML lets a tag carry both attributes and text, which JSON has no direct equivalent for. xml2js handles this by placing attributes under a $ key and the element's own text under _. So <item id="7">Pen</item> becomes { "item": { "$": { "id": "7" }, "_": "Pen" } }. It's a faithful representation rather than a lossy flattening, which means you can round-trip the structure if you need to.

One thing to watch for

  • Every leaf value comes back as a string — XML has no number or boolean types, so <active>true</active> becomes "true", not true. Cast on your side if you need real types.
  • Element order is preserved within objects, but JSON object key order is not something every consumer respects — don't rely on it for logic.
  • Comments and processing instructions in the XML are dropped; only data carries over.

Frequently asked questions

XML stores everything as text — there's no concept of a numeric or boolean type. The converter faithfully returns those values as strings. If you need real numbers or booleans, cast them in your own code after conversion.

That's where xml2js puts an element's attributes. For example id="7" on a tag becomes a $ object containing { id: "7" }. The element's own text, if any, lands under a _ key alongside it.

The converter uses explicitArray: false, so an element only becomes an array when it actually appears more than once. A tag that occurs a single time stays a plain object, which keeps the JSON tidy.

No. The whole conversion runs in your browser using xml2js. You could disconnect from the internet and it would still work, which is why it's safe for sensitive payloads.

Yes — head to the JSON to XML converter to reverse the transformation. Bear in mind the round-trip won't be byte-identical, since comments and exact whitespace aren't preserved.

The parser couldn't read the document. The usual culprits are an unclosed or mismatched tag, more than one root element, or an unescaped & or < inside text. Fix the flagged issue and the JSON reappears.

Need another tool?

Browse the full toolbox or dig into the blog for the engineering behind it.

Call UsWhatsApp