3 min read
Free XML to JSON Converter
Convert XML to JSON online for free. Parse XML in your browser, preserve attributes and repeated elements, and copy or download formatted JSON.
The converter uses documented mapping rules and processes input locally. You can also use our JSON Formatter and Validator or YAML to JSON Converter.
XML to JSON Converter
Convert XML into readable JSON in your browser. Copy the result or download a JSON file.
Maximum input size: 1 MB. Input is processed locally in your browser.
Choose an XML file up to 1 MB. The file stays in your browser, you can also paste XML below.
Ready for conversion.
Conversion rules: the root element becomes the top-level JSON key; attributes use an @ prefix; text in elements with attributes but no children uses #text; mixed text and child elements use #content in document order; repeated #text; repeated child elements become arrays. Comments and processing instructions are ignored. Namespace prefixes are preserved.
How to convert XML to JSON
- Paste well-formed XML into the input panel.
- Select Convert to JSON.
- Review the result, then copy it or download the JSON file.
Conversion uses the browser's built-in XML parser. Your XML is not sent to a Ccodelearner conversion server.
XML to JSON conversion rules
XML and JSON represent data differently, so this tool applies consistent rules:
- Root element: becomes the top-level JSON property.
- Attributes: use an
@prefix, such as"@id". - Text: text-only elements become strings. Mixed text and child elements are stored in a #content array in document order. Text in an element that also has attributes or child elements uses
#text. - Repeated elements: elements with the same child name become an array.
- Empty elements: become an empty string when they contain no attributes, text or child elements.
- Namespaces: prefixes remain in element and attribute names.
These are documented conversion conventions, not a universal XML-to-JSON standard. Review the output if your application expects a different mapping.
Example: XML to JSON
XML input
<book id="bk101">
<title>XML Developer Guide</title>
<tag>XML</tag>
<tag>JSON</tag>
</book>JSON output
{
"book": {
"@id": "bk101",
"title": "XML Developer Guide",
"tag": ["XML", "JSON"]
}
}When should you convert XML to JSON?
- APIs: transform XML responses for JavaScript applications.
- Web apps: work with data in applications that expect JSON objects.
- Data migration: reshape exported records for a JSON-based workflow.
- Debugging: inspect nested data and attributes in a readable format.
Frequently asked questions
Is the XML to JSON converter free?+
Yes. Convert XML, copy the result and download JSON without creating an account.
Is my XML uploaded?+
No. The conversion runs in your browser; your XML is not sent to a Ccodelearner conversion endpoint.
How are attributes handled?+
Attributes become JSON properties prefixed with @. For example, id="bk101" becomes "@id": "bk101".
What happens to repeated elements?+
Repeated child elements with the same name become an array, even when there are only two.
Does it support every XML document?+
It supports well-formed XML accepted by the browser parser. DOCTYPE and custom entity declarations are intentionally rejected. Some specialised XML formats may require application-specific rules.
Are numbers and booleans converted to JSON types?+
Element text and attribute values remain strings. This avoids guessing whether values such as 0012, true or dates should be treated as numbers, booleans or strings.
Related developer tools
Explore the JSON Formatter and Validator, YAML to JSON Converter and JSON to YAML Converter.