XML to JSON Converter
XML (eXtensible Markup Language) uses nested tags with attributes; JSON (JavaScript Object Notation) uses key-value pairs with braces and brackets. To convert: elements become object keys, text content becomes string values, attributes become @-prefixed keys (e.g., @id), repeated elements become arrays. CDATA sections are extracted as plain text. Self-closing tags become empty strings.
Convert XML to JSON instantly in your browser. Handles attributes (as @attr), nested elements, arrays, CDATA, self-closing tags, and comments. Presets for RSS feeds, config files, and SVG. Adjustable indentation. Free, private, no data sent to any server.
XML Input
JSON Output
Quick Examples
XML to JSON Conversion Rules
| XML | JSON | Example |
|---|---|---|
| <tag>text</tag> | {"tag": "text"} | Element with text becomes key-value pair |
| <tag attr="val"> | {"@attr": "val"} | Attributes prefixed with @ |
| Multiple same-name children | {"tag": [...]} | Repeated elements become arrays |
| <tag /> | {"tag": ""} | Self-closing tag becomes empty string |
| <![CDATA[...]]> | {"tag": "raw text"} | CDATA content preserved as text |
How to Use
- 1
Paste your XML
Paste or type XML into the input area — the tool validates and converts it automatically
- 2
View the JSON output
The converter instantly transforms your XML into properly formatted JSON with attributes, arrays, and nested objects
- 3
Adjust formatting
Choose 2-space, 4-space, or minified JSON output using the indent selector
- 4
Try a preset
Click a quick example like RSS Feed or Config File to see the conversion in action
- 5
Copy the result
Click the copy button to copy the JSON output to your clipboard
Frequently Asked Questions
- How do I convert XML to JSON?
- Paste your XML into the input area and the tool converts it to JSON instantly. Elements become object keys, text content becomes string values, attributes become @-prefixed keys, and repeated elements become arrays.
- How are XML attributes handled in JSON?
- XML attributes are converted to JSON keys prefixed with @. For example, <book category="fiction"> becomes {"@category": "fiction"}. This convention (used by libraries like xml2js) preserves attribute data without conflicting with child element names.
- What happens when XML has multiple elements with the same name?
- Repeated sibling elements with the same tag name are grouped into a JSON array. For example, two <item> elements become "item": [{...}, {...}]. A single element stays as an object, not an array.
- Does this tool handle CDATA sections?
- Yes. CDATA sections (<![CDATA[...]]>) are extracted as plain text content. The CDATA wrapper is removed and the raw text is preserved in the JSON output as a string value.
- Can I convert RSS or Atom feeds to JSON?
- Yes. Paste the RSS or Atom XML and the tool converts the entire feed structure to JSON, including channel info, items, titles, links, and dates. Use the RSS Feed preset for an example.
- Is my XML data sent to a server?
- No. All parsing and conversion runs entirely in your browser using JavaScript. No data is transmitted to any server. The tool works offline once the page is loaded.