Skip to content

XML to JSON Converter

Turn an XML document into JSON, keeping attributes, repeated elements and text content in a predictable structure.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is XML to JSON Converter?

XML and JSON model data differently, so every converter has to pick conventions. Here an element becomes a key, repeated sibling elements become an array, attributes become keys starting with a prefix (default @_), and the text of an element that also has attributes or children goes into a #text key.

The conversion uses fast-xml-parser with safe settings. Values stay strings by default so that codes like 007 do not lose their zeros; you can opt in to number and boolean conversion. The XML declaration and processing instructions are dropped, CDATA is merged into text, and the five predefined entities plus numeric character references are decoded. Documents that declare entities are rejected to prevent “billion laughs” and XXE attacks.

How does it work?

  1. Paste your XML.
  2. Set the attribute prefix and the text node name, or disable attributes altogether.
  3. Optionally enable conversion of numbers and booleans and choose the output indentation.
  4. Copy or download the JSON, or Swap to convert it back with JSON to XML.

Common use cases

  • Consuming a SOAP or legacy XML API from a JavaScript front end.
  • Converting an RSS or sitemap file to JSON for processing.
  • Inspecting an XML export with JSON tooling such as the JSON Viewer or JSONPath.
  • Migrating XML configuration to JSON or YAML.

Examples

Try this input in the tool above:

Input
<?xml version="1.0"?>
<catalog lang="en">
  <book id="bk101">
    <title>XML Developer's Guide</title>
    <price currency="USD">44.95</price>
  </book>
  <book id="bk102">
    <title>Midnight Rain</title>
    <price currency="USD">5.95</price>
  </book>
</catalog>
Output
{
  "catalog": {
    "book": [
      {
        "title": "XML Developer's Guide",
        "price": {
          "#text": "44.95",
          "@_currency": "USD"
        },
        "@_id": "bk101"
      },
      {
        "title": "Midnight Rain",
        "price": {
          "#text": "5.95",
          "@_currency": "USD"
        },
        "@_id": "bk102"
      }
    ],
    "@_lang": "en"
  }
}

Privacy

XML to JSON Converter runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

XML features with no JSON equivalent are lost: comments, processing instructions and the order of interleaved text and elements (mixed content). One repeated element becomes an object, two or more become an array, so array shapes depend on the data.

Frequently asked questions

Why is my single child element an object instead of an array?

The converter cannot know the schema: one <item> becomes an object, two or more become an array. Handle both shapes in code, or use a schema-aware tool when the shape must be fixed.

Are XML entities and DOCTYPE processed?

The five predefined entities and numeric references are decoded. A DOCTYPE that declares entities is rejected with an explanation, because such documents can be used for exponential expansion or to read local files in unsafe parsers.

Are numbers converted?

Not by default: every value is a string, which is lossless. Enable “Convert numbers & booleans” to get numeric and boolean JSON values; leading-zero values such as 007 stay strings.

More tools in JSON & Data →