InTab

XML to JSON Converter

Convert XML documents to JSON, keeping attributes, and back again.

Converters: Turn one format into another. It runs in your browser, so nothing you enter is uploaded.

What it does

The XML to JSON Converter turns XML into JSON while keeping the attributes, and converts JSON back to XML. Use it to work with SOAP or RSS responses, old configuration files or exported data in JavaScript and modern APIs.

How to use it

  1. Paste XML, open a file, or click Load sample.
  2. Choose the indent.
  3. Copy or download the JSON.
  4. Click Swap direction to turn JSON into XML.

Example

<book id="bk101" lang="en">
  <title>XML Guide</title>
  <price currency="USD">44.95</price>
  <tag>xml</tag>
  <tag>dev</tag>
</book>

As JSON:

{
  "book": {
    "title": "XML Guide",
    "price": {
      "#text": 44.95,
      "@_currency": "USD"
    },
    "tag": [
      "xml",
      "dev"
    ],
    "@_id": "bk101",
    "@_lang": "en"
  }
}

How the mapping works

  • Attributes become keys starting with @_.
  • When an element has attributes and text, the text is stored under #text.
  • Repeated elements become an array.
  • Numbers and booleans are converted to JSON numbers and booleans.

FAQ

Why is a single <tag> not an array? With only one element there is nothing to show it repeats. Code that reads the JSON should accept both a single value and an array.

Can I get typed classes instead of JSON? Use XML to Code for C#, Java, Go or TypeScript.

Guides

More Converters tools

  • JSON to Code: Generate TypeScript, C#, Java, Python, Go, Kotlin, Swift, Rust, PHP, Dart types from JSON.
  • XML to Code: Generate C# (XmlSerializer), Java (JAXB), Go and TypeScript classes that read your XML.
  • Data Format Converter: Convert between JSON, YAML, XML, CSV and TOML in any direction.
  • JSON to YAML Converter: Turn JSON into clean YAML (and back) for configs, Kubernetes and CI files.
  • Number Base Converter: Convert numbers between binary, octal, decimal and hexadecimal.
  • Color Converter: Convert colors between HEX, RGB, HSL, HSV and CMYK.
  • Case Converter: camelCase, snake_case, kebab-case, PascalCase and more.