XML to JSON Converter
Convert XML to JSON with attributes, repeated elements and CDATA handled properly, or turn JSON back into XML. Long IDs and codes with leading zeros stay exactly as written.
Converted in your browser; nothing is uploaded.
Related Developer Tools
This converter turns XML from SOAP services, RSS feeds, exports and older APIs into JSON you can use directly in JavaScript, and turns JSON back into XML when a system still expects it. Attributes, repeated elements, namespaces and CDATA are handled, and the conventions are adjustable so the output matches what your library or API uses.
How XML Maps to JSON
| XML | JSON |
|---|---|
<name>Ali</name> | "name": "Ali" |
<item id="7"/> | "item": { "@id": 7 } |
<price cur="USD">9.5</price> | "price": { "@cur": "USD", "#text": 9.5 } |
<tag>a</tag><tag>b</tag> | "tag": ["a", "b"] |
<empty/> | "empty": "" |
<![CDATA[a & b]]> | "a & b" (plain text) |
<x:note> (namespace prefix) | "x:note", with "@xmlns:x" kept as an attribute |
Choosing the Options
- Attribute prefix: @ is common in converters and readable; @_ matches the default of the popular fast-xml-parser library; - and _ suit code that cannot use @ in property names easily.
- Always use arrays: turn on when the JSON feeds code that loops over lists, so one item and many items have the same shape.
- Numbers & true/false: leave on for data you will calculate with; turn off when values are codes, phone numbers or anything that must be kept as text.
- Root if needed: XML must have exactly one root element. When the JSON is an array or has several top-level keys, the result is wrapped in an element with this name.
Related Tools
Check and indent the XML first with the XML formatter, tidy the JSON with the JSON formatter, turn it into a spreadsheet with JSON to CSV, or generate types for it with JSON to TypeScript.
Frequently Asked Questions
How do I convert XML to JSON?
Paste the XML or open an .xml file, and the JSON appears on the right as you type. The XML is first checked with your browser's XML parser, so a syntax error is reported with its line and column instead of producing half a result. Copy the JSON or download it as a file.
How are XML attributes shown in JSON?
As keys with a prefix, @ by default: <item sku="BK-101"> becomes "@sku": "BK-101". You can switch to @_, - or _ to match what your code or library expects. When an element has both attributes and text, the text goes under #text (or the key you choose).
Why is a single item not an array?
XML does not say whether an element can repeat. Two <item> elements become an array, but a single one becomes a plain object, which can break code that loops over the list. Turn on Always use arrays to make every element an array, so the shape stays the same whatever the number of items.
Are numbers converted?
With Numbers & true/false as values on, text such as 42, 4.5 and true becomes a JSON number or boolean. Text that would change if converted stays a string: codes with leading zeros like 007, prices written as 1.50, and IDs too long for a JavaScript number. Turn the option off to keep every value as a string.
How do I convert JSON to XML?
Switch to JSON → XML and paste the JSON. Keys become element names, arrays become repeated elements, and keys starting with the attribute prefix become attributes, so JSON made by this converter turns back into the same XML structure. Keys that are not valid XML names, such as "first name" or "1st", are renamed (first_name, _1st), and the tool lists what it changed.
What gets lost in the conversion?
JSON has no comments, processing instructions or ordering between text and child elements. Comments can be kept under #comment, but where text is mixed with child elements, as in <p>Some <b>bold</b> text</p>, the text and children are stored separately. For documents like that, XML is the better format to keep.