XML to JSON Converter

Convert XML to JSON in your browser with a clear, documented mapping. Attributes...

SecureFastFree

Updated

XML input0 B
JSON output
0 B
JSON output will appear here...

How the mapping works

Element
<city>Paris</city>
becomes
{ "city": "Paris" }
Attribute
<a id="1">hi</a>
becomes
{ "@id": "1", "#text": "hi" }
Repeated
<i>A</i><i>B</i>
becomes
{ "i": ["A", "B"] }
CDATA
<n><![CDATA[<b>]]></n>
kept raw
{ "n": "<b>" }

Quick answer

To convert XML to JSON, paste your XML into the input box and the tool parses it in your browser and shows JSON instantly. Element names become object keys, attributes are prefixed with @ (for example <a id="1"> becomes {"@id": "1"}), text sits under #text, and repeated sibling elements become arrays. CDATA is kept raw and nothing is uploaded, so it works offline and stays private. Choose the indent, then copy or download the .json file.

SSL Secured
256-bit Encryption
Cloud Processing
Mobile Friendly

Converter Features

Live Conversion - JSON updates as you type
Attribute Prefix - Toggle the @ prefix on or off
Array Control - Auto arrays or always arrays
CDATA Safe - CDATA kept raw, never escaped
Error Reporting - Line and column on bad XML
Copy & Download - Copy or save as a .json file

Why Use XML to JSON Converter?

Instant, Live Conversion

Paste XML and the JSON updates as you type, with your chosen indent. No button to hunt for and no page reloads.

A Clear, Documented Mapping

Elements become keys, attributes are prefixed with @, text sits under #text, and repeated elements become arrays. The rules are shown on the page.

Smart Array Detection

Repeated sibling elements collapse into a JSON array automatically. Prefer arrays everywhere? Turn on Always use arrays for a stable shape.

Keeps CDATA Raw

CDATA content is preserved byte-for-byte and never escaped or trimmed, so markup and characters like < and & inside a block survive intact.

Friendly Error Messages

Malformed XML never crashes the tool. You get a plain-English message with the exact line and column so you can fix it fast.

100% In Your Browser

Every byte is parsed on your device with no upload, so there are no file-size limits, it works offline, and your data stays private.

Common Uses for XML to JSON

API Integration

Convert an XML or SOAP API response to JSON so you can work with it directly in JavaScript.

Data Migration

Transform XML exports into JSON for document databases like MongoDB or for a modern data pipeline.

Config Conversion

Turn an XML config file into JSON for tools and frameworks that expect JSON input.

Feeds & Sitemaps

Convert an RSS, Atom or sitemap.xml document to JSON to inspect or reshape its entries.

How It Works

1

Paste Your XML

Drop in an XML document, API response, config file or feed. Or hit Load sample to see the converter in action.

2

Set the Options

Pick 2, 4 or tab indent, toggle the @ attribute prefix, choose whether single children become arrays, and trim text whitespace if you like.

3

Copy or Download

The JSON updates live. Copy it to your clipboard or download it as a .json file. Everything happens locally in your browser.

Tips for XML to JSON Conversion

Keep the @ Prefix On

The @ prefix keeps attributes and child elements distinct, which prevents key collisions and matches common conventions like those in xml-js and fast-xml-parser.

Use Always Use Arrays for Stable Shapes

If your code maps over children, turn on Always use arrays so a single element and many elements both produce an array, avoiding branchy parsing code.

One Root Element Only

A well-formed XML document has exactly one root element. If you paste several top-level elements, wrap them in a single parent element first.

Frequently Asked Questions

Paste your XML into the input box and the tool parses it in your browser and shows JSON instantly, with no upload. Element names become object keys, attributes are prefixed with @, text content sits under #text, and repeated sibling elements become arrays. Then pick your indent and copy or download the JSON.
Elements become object keys, so <city>Paris</city> becomes {"city": "Paris"}. Attributes are prefixed with @ by default, so <a id="1">hi</a> becomes {"a": {"@id": "1", "#text": "hi"}}. An element with only text collapses to that string. Repeated sibling elements become an array, and the whole document is wrapped under its single root element. Empty elements become an empty string.
Each attribute becomes a key prefixed with @ so it never clashes with a child element of the same name. For example <book id="bk101"> becomes {"@id": "bk101"}. You can turn the prefix off to merge attributes as plain keys, but a prefix is the safe default because it keeps attributes and child elements distinct.
If an element has only text, it collapses straight to that string, so <name>John</name> becomes {"name": "John"}. If the element also has attributes or child elements, its text is placed under a #text key so nothing is lost, for example {"@id": "1", "#text": "John"}. Regular text is entity-decoded, so &amp; becomes an ampersand.
When two or more sibling elements share a tag name, they become a JSON array in document order, so <r><i>A</i><i>B</i></r> becomes {"r": {"i": ["A", "B"]}}. A single element stays an object by default. If you want every child to be an array for a predictable shape, turn on the Always use arrays option.
Yes. CDATA content is kept raw and treated as text, byte-for-byte, and it is never escaped, entity-decoded or trimmed. So <n><![CDATA[ <b> & ]]></n> becomes {"n": " <b> & "}, with the inner markup and spacing intact.
Instead of crashing or showing a blank result, the tool reports a friendly, specific error. Mismatched tags, unclosed tags, stray closing tags and unterminated comments or CDATA are each described with the exact line and column so you can fix them quickly.
Yes. The converter runs entirely in your browser using client-side JavaScript, with no DOMParser or server round trip. Your XML is never uploaded, so there are no file-size limits and the tool works even offline.
Namespace prefixes are preserved as part of the element or attribute name, so <ns:item> becomes the key "ns:item". For complex namespace handling you may want to simplify or strip the declarations before converting.

Related Tools