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:
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
- 1Paste your XML into the left editor (from a SOAP response, RSS feed, config file, etc.).
- 2The right pane instantly renders the JSON equivalent, indented for readability.
- 3Switch the attribute prefix (@, $, _, or none) to match the JSON library you plan to feed downstream.
- 4Enable 'Parse numbers & booleans' if you want typed values in the output — leave it off to keep everything as strings for lossless round-trip.
- 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 (< > & " ') and numeric character references (☃ / ☃) 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
JSON → TypeScript
Convert JSON to TypeScript interfaces instantly. Generate strongly-typed TS types from any JSON sample.
JSON → Go
Convert JSON to Go structs online. Generates idiomatic Go structs with proper json tags and PascalCase field names.
JSON → Python
Convert JSON to Python @dataclass definitions with typed fields. snake_case field names, nested classes, List[T] for arrays, and JSON-key alias comments. 100% local.
JSON → PHP
Convert JSON to PHP 7.4+ classes with typed properties. Generates one class per nested object, phpdoc @var array<T> for typed arrays, and camelCase property names. 100% local.
JSON → Java
Convert JSON to Java POJOs with Jackson @JsonProperty annotations, camelCase field names, List<T> for arrays, and generated getters/setters. Optional package declaration. 100% local.
JSON → C#
Convert JSON to C# classes with System.Text.Json [JsonPropertyName] attributes, PascalCase properties, List<T> for arrays, and optional namespace. Works in .NET 6 / 7 / 8 / 9. 100% local.