XML to JSON Converter

Input XML

Output JSON

Your JSON appears here as you type.

Paste data to see token savings

Convert XML documents to JSON for modern web applications.

Example: XML input and real JSON output

The output below was generated by the same conversion code the converter uses, run on this sample when the page was built.

XML input (296 characters)
<catalog>
  <book id="bk101">
    <title>Designing Data-Intensive Applications</title>
    <author>Martin Kleppmann</author>
    <year>2017</year>
  </book>
  <book id="bk102">
    <title>The Pragmatic Programmer</title>
    <author>Andrew Hunt</author>
    <year>1999</year>
  </book>
</catalog>
JSON output (341 characters)
{
  "catalog": {
    "book": [
      {
        "title": "Designing Data-Intensive Applications",
        "author": "Martin Kleppmann",
        "year": 2017,
        "@_id": "bk101"
      },
      {
        "title": "The Pragmatic Programmer",
        "author": "Andrew Hunt",
        "year": 1999,
        "@_id": "bk102"
      }
    ]
  }
}

JSON output is 15% larger than the XML input. The same data is 214 characters as minified JSON and 341 as pretty-printed JSON. Sizes are character counts, not tokens: token counts depend on the model's tokenizer (see the tokenizer comparison).

XML to JSON: what changes

  • The id attribute shows up as "@_id", and the two <book> elements become an array. If a document has only one <book>, the same path becomes an object instead, so code reading the JSON should handle both shapes.
  • Reading XML: Attributes are kept with an @_ prefix (id="bk101" becomes "@_id"), repeated child elements become arrays, and numeric text becomes numbers. A single child element becomes an object, not a one-item array, so the shape depends on how many elements appear.
  • Writing JSON: Output is pretty-printed with your chosen indentation. JSON is the safest target when the data goes into code, an API, or another tool.

About XML

Extensible Markup Language is a verbose but powerful format. Still widely used in legacy systems, SOAP APIs, and document formats.

  • ✓Rich metadata
  • ✓Namespaces
  • ✓Validation schemas
  • ✓Legacy support
Full XML Documentation →

About JSON

JavaScript Object Notation is the most widely used data interchange format. Lightweight, easy to parse, and supported by every programming language.

  • ✓Universal compatibility
  • ✓Easy to parse
  • ✓Great for APIs
  • ✓Native in JavaScript
Full JSON Documentation →

Why Convert XML to JSON?

Use JSON when you need maximum compatibility with other systems, APIs, or programming languages. It's the de facto standard for web APIs and data exchange.

XML to JSON: Frequently Asked Questions

How do I convert XML to JSON?

Paste your XML into the editor on json2toon.co. The tool detects the input and produces JSON instantly, then you copy the result. Conversion runs entirely in your browser, so nothing is uploaded to a server.

Is the XML to JSON converter free?

Yes. Converting XML to JSON on json2toon.co is free with no account, signup, or usage limit. A free public API is also available for automated, programmatic conversion.

Why convert XML to JSON?

Convert XML documents to JSON for modern web applications.

What should I watch out for when converting XML to JSON?

The id attribute shows up as "@_id", and the two <book> elements become an array. If a document has only one <book>, the same path becomes an object instead, so code reading the JSON should handle both shapes.

Is my data safe when I convert XML to JSON?

Yes. The XML to JSON conversion happens client-side in your browser. Your source data stays on your device and is never sent to or stored on a server, which makes it safe for private or sensitive payloads.