XML to JSON Converter
CV-05Paste XML and get JSON back. Attributes become keys that start with @, repeated elements become arrays, and text that sits next to attributes or child elements goes under "#text".
Runs in your browser. Nothing is uploaded.
XML
JSON
How to use it
- Paste your XML into the input box, or open an .xml file (up to 5 MB) or drop it on the box.
- The JSON appears as you type. Choose 2 spaces, 4 spaces or Tab for the indent.
- Read the result: keys that start with @ are attributes, and "#text" is text beside attributes or child elements.
- Copy the JSON or download it as a .json file.
How XML becomes JSON
XML and JSON do not match one to one, so the converter follows a fixed rule. The root element becomes the single top-level key. An attribute becomes a key that starts with @, so id="1" is "@id": "1". An element that holds only text becomes a string, and an empty element such as <empty/> becomes "". When an element holds attributes or child elements plus text, the text goes under "#text".
Repeated elements and single elements
An element that appears more than once under the same parent becomes an array. An element that appears once stays a single value. That means the same element is an object in one document and an array in another, depending on how many times it occurs, so code that reads the JSON should handle both. Elements are grouped by name, so if different elements were interleaved in the XML, each name is grouped at the position of its first appearance.
What is dropped or changed
Comments, processing instructions, the XML declaration and the DOCTYPE are not carried over. Text is trimmed at both ends, CDATA is read as ordinary text, and every value stays a string, so 007 and true are not turned into numbers or booleans. Only the five built-in entities and numeric references such as © are decoded. A custom entity is an error. Namespace prefixes stay part of the name, and nothing is checked against a schema.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Expected </book> (opened on line 2) but found </catalog> at line 4, column 3 | A closing tag does not match the element that is currently open, so a tag was left open or closed in the wrong order. | Close the element named in the message, or fix the nesting, then convert again. |
<catalog> opened on line 1 is never closed at line 5, column 1 | The text ended while this element was still open. | Add the missing closing tag, or make the element self-closing if it has no content. |
A "&" must be written as & (or start an entity such as <) at line 1, column 9 | A bare ampersand appears in text or an attribute. XML reads it as the start of an entity. | Replace & with & wherever it is plain text. |
Unknown entity (only < > & " ' and numeric references such as © are read) at line 1, column 4 | The text uses a named entity that XML does not define on its own. HTML names such as only work in HTML. | Use a numeric reference such as  , or the character itself. |
An XML document can have only one root element at line 1, column 8 | A second top-level element starts after the first one has closed. | Wrap everything in one parent element. |
No root element found. XML needs one element such as <root>...</root> | The input has no element, only a declaration, comments or blank text. | Add the root element and its content. |
Questions people ask
How do I convert XML to JSON?
Paste the XML into the input box. The JSON appears as you type, with the root element as the top-level key. Attributes become keys that start with @ and repeated elements become arrays. Copy the result or download it as a .json file.
How are XML attributes shown in JSON?
Each attribute becomes a key on the element's object, with @ in front of the name. So <book id="1"> gives "@id": "1". If the element also has text, that text is stored under "#text" next to the attribute keys.
Why is one element an object and another an array?
An element that appears once under a parent stays a single value, and one that repeats becomes an array. XML has no way to say a list has one item, so a list of one comes out as a plain value. Check for both shapes in the code that reads the JSON.
Does it turn numbers and true or false into JSON types?
No. Every value stays a string, so 007 keeps its zeros and 12345678901234567890 is not rounded. Convert types afterwards in your own code, where you know which fields are numbers.
What happens to comments, CDATA and namespaces?
Comments are dropped. A CDATA section is read as text, with the angle brackets and ampersands inside it kept. Namespace prefixes stay in the names, so xs:element is the key "xs:element", and xmlns attributes appear as "@xmlns:xs" keys.
Is my XML uploaded when I convert it?
No. The XML is parsed in your browser and nothing is sent to a server. Files must be under 5 MB. A share link keeps your input after the # in the address, which browsers never send to a server.
About this tool
The rules: the root element becomes the one top-level key. An attribute becomes a key that starts with @. Text next to attributes or child elements goes under "#text". An element that appears more than once under the same parent becomes an array, and one that appears once stays a single value, so the shape can differ between documents. An element with only text becomes a string, and an empty element becomes "". Every value is text: numbers and true/false are not converted. Not kept: comments, processing instructions, the XML declaration and the DOCTYPE, and the order of text mixed between child elements. Text is trimmed at both ends, and CDATA is read as plain text. Only the five built-in entities and numeric references such as © are decoded; custom entities are an error. Elements are grouped by name, so different elements that were interleaved come out grouped under the position of their first appearance. Namespace prefixes are kept as part of the name. It does not validate against a schema.