XML to JSON Converter
XML to JSON ConverterConvert Data
About XML to JSON
Convert XML documents to JSON format. XML attributes can be preserved with a configurable prefix. Text content in mixed elements uses a special key. Arrays are automatically created for repeated elements with the same tag name.
Related Tools
What is XML to JSON Conversion?
XML to JSON conversion transforms XML (eXtensible Markup Language) documents into JSON (JavaScript Object Notation) format. This is essential when integrating systems that use different data formats or when modernizing legacy applications.
XML uses a hierarchical structure with tags, attributes, and text content, while JSON uses a simpler key-value pair structure with objects and arrays. Our converter intelligently maps XML elements to JSON properties.
This free tool handles XML attributes, repeated elements (converted to arrays), mixed content, and nested structures. All processing happens in your browser for privacy and speed.
Features
Attribute Handling
XML attributes are preserved with a customizable prefix (@_, @, _, or none) to distinguish them from child elements.
Array Detection
Repeated elements with the same tag name are automatically converted to JSON arrays.
Customizable Output
Choose indentation style (2 spaces, 4 spaces, tabs, or minified) for the output JSON.
Mixed Content Support
Elements with both text content and child elements use a configurable text key (#text, _text, etc.).
Download & Copy
Download the converted JSON as a file or copy it directly to your clipboard.
Error Detection
Invalid XML is detected and reported with helpful error messages.
XML to JSON Conversion Rules
Elements to Objects: XML elements become JSON object properties with the tag name as the key.
Attributes to Properties: XML attributes are converted to properties with a prefix (e.g., @_id).
Repeated Elements to Arrays: Multiple elements with the same name become a JSON array.
Text Content: Simple text content becomes a string value; mixed content uses a text key.
Empty Elements: Empty elements are represented as null in JSON.
CDATA Sections: CDATA content is treated as text content.
Frequently Asked Questions
How are XML attributes handled?
XML attributes are converted to JSON properties with a prefix to distinguish them from child elements. You can choose the prefix (@_, @, _, or none) in the options.
What happens to repeated XML elements?
When multiple XML elements have the same tag name at the same level, they are automatically combined into a JSON array. Single elements remain as individual values.
Can I convert JSON back to XML?
Not directly with this tool. JSON to XML conversion requires different handling due to the structural differences between the formats. We may add this feature in the future.
Is my data secure?
Yes. All processing happens entirely in your browser using JavaScript. Your XML data never leaves your device and is not sent to any server.