DevKits

XML to JSON Converter — Online, Free, No Upload

Convert XML to JSON online. Handles attributes, CDATA, nested elements, and repeated siblings. Compatible with fast-xml-parser / xml2js output conventions. 100% local.

Last updated:

330 chars · 13 lines
{
"library":{
"book":[
0:{ 5 keys }
1:{ 5 keys }
]
}
}

Paste XML on the left to get a JSON object with attributes as @-prefixed keys, text as #text, and repeated siblings collapsed into arrays. Compatible with fast-xml-parser / xml2js conventions. All local in your browser.

What is XML → JSON?

An XML to JSON converter turns an XML document into a structured JSON representation you can pipe into JavaScript, Python, or any modern service. The tricky part is that XML has three concepts JSON doesn't: attributes, mixed content, and named-but-repeatable siblings. This tool applies the industry-standard mapping used by fast-xml-parser and xml2js: attributes become @-prefixed keys, text content lives under #text, and repeated siblings are automatically collapsed into arrays. Parsing runs on a hand-written tokenizer (no DOMParser dependency), so it works in Node, edge functions, and any browser without extra polyfills.

How to convert XML to JSON online

  1. 1Paste your XML into the left editor (from a SOAP response, RSS feed, config file, etc.).
  2. 2The right pane instantly renders the JSON equivalent, indented for readability.
  3. 3Switch the attribute prefix (@, $, _, or none) to match the JSON library you plan to feed downstream.
  4. 4Enable 'Parse numbers & booleans' if you want typed values in the output — leave it off to keep everything as strings for lossless round-trip.
  5. 5Copy the result or switch to Tree view for a structural preview before shipping.

Use Cases

Consume legacy SOAP APIs

Modern JS/TS pipelines are much easier to write against JSON. Convert SOAP responses at the ingress layer and treat the rest of the codebase as JSON-native.

Read RSS / Atom feeds

RSS is XML by definition. Converting to JSON lets you filter, transform, and template feed items with any JSON-oriented toolkit.

Migrate old configs

web.config, log4j.xml, and other legacy XML configs are easier to reason about — and easier to diff — in JSON form.

Inspect webhook payloads

Some ERP and finance systems still emit XML webhooks. Convert to JSON to view them in modern debugging tools like Postman or Bruno.

Code Examples

Input XML

<library>
  <book id="b1">
    <title>Refactoring</title>
    <author>Martin Fowler</author>
  </book>
</library>

Output JSON

{
  "library": {
    "book": {
      "@id": "b1",
      "title": "Refactoring",
      "author": "Martin Fowler"
    }
  }
}

Do it in Node.js with fast-xml-parser

import { XMLParser } from "fast-xml-parser";
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "@" });
const obj = parser.parse(xml);

Key Concepts

Attribute vs. element
XML distinguishes <book id="b1"> (attribute) from <book><id>b1</id></book> (child element). JSON has no such distinction, so the tool marks attributes with a configurable prefix.
Mixed content
XML allows text and child elements to interleave inside the same parent. When mixed content is detected, the text goes under #text and children keep their own keys.
Sibling → array coercion
Two or more <book> siblings become an array of book objects. A lone <book> stays a scalar — this is convenient but can bite you when a variable-cardinality element is sometimes an array and sometimes not.
Lossy vs. lossless
String values → JSON strings is lossless. Enabling 'Parse numbers & booleans' introduces coercion ("123" → 123, "true" → true) that can lose information for zero-padded IDs, phone numbers, or the literal string "true".

Tips & Best Practices

  • For always-array coercion (so downstream code doesn't need to type-check), post-process the JSON to wrap known collections in arrays even when they have a single element.
  • If your XML has namespaces (xmlns:soap, etc.), they appear literally in the tag names in the JSON output. Strip them with a JSON transformer if you don't care about the namespace.
  • CDATA blocks are preserved as text but not marked — if you need to distinguish CDATA from a normal text node, wrap it in a sentinel string before conversion.
  • For very large XML documents (>10 MB), streaming parsers like sax-js are more memory-efficient than this tool's in-memory approach.
  • Round-tripping XML → JSON → XML is not always identical: whitespace between elements and attribute order aren't preserved. Semantic content is.

Frequently Asked Questions

How are XML attributes represented in the JSON output?

Attributes are prefixed with @ by default (e.g. <book id="b1"> becomes { "@id": "b1" }), matching fast-xml-parser and jq's convention. You can switch the prefix to $, _, or none in the toolbar.

How are repeated sibling elements handled?

When an element appears multiple times with the same tag name inside the same parent, it's collapsed into a JSON array automatically. Single occurrences stay as a scalar or object.

Are numbers and booleans parsed automatically?

XML is untyped — every value is a string. This tool keeps values as strings by default (lossless round-trip). Enable 'Parse numbers & booleans' to coerce true/false/integers/floats where the format matches, at the cost of a lossy conversion.

Does it handle CDATA and XML entities?

Yes. CDATA blocks are merged into the containing text node. Standard XML entities (&lt; &gt; &amp; &quot; &apos;) and numeric character references (&#x2603; / &#9731;) are decoded during conversion.

Is my XML uploaded to any server?

No. Parsing and conversion run entirely in your browser as client-side JavaScript. Nothing is transmitted.

Related Tools