What This Tool Does
The XML to JSON Converter converts XML files in your browser. Use the controls to choose how attributes, text, the JSON root, encoding, and output formatting are handled, then review the JSON preview before downloading.
How to Convert XML to JSON
- Drop one or more XML files into Drop XML files here, or click browse files.
- Set Input encoding to Auto-detect or choose UTF-8, UTF-16 LE, ISO-8859-1 (Latin-1), or Windows-1252.
- Choose an Attribute handling mode and edit Attribute prefix if you use Prefix keys.
- Set Text content key if you want a key other than
#textfor mixed text content. - If repeated direct child elements are detected, choose a JSON root.
- Choose Output format. For Pretty (indented), select 2 spaces, 4 spaces, or Tab under Indent size. Choose Compact (minified) for unformatted JSON.
- Choose whether to Trim whitespace in text. Leave Ignore XML declaration unchecked to include declaration metadata under
?xmlwhen present, or check it to omit that metadata. - Review the automatically generated JSON preview, then download each JSON file or click Download all as ZIP.
Attribute Handling Options
Choose how XML attributes become JSON keys:
- Prefix keys uses the editable Attribute prefix, which defaults to
@_. - Group under @attributes places attributes in an
@attributesobject. - Merge with elements writes attributes as plain keys alongside element keys.
- Ignore attributes leaves attributes out of the JSON.
JSON Roots, Text, and Repeated Elements
The JSON root selector appears when the tool detects repeated direct child elements. Repeated sibling elements with the same tag name become a JSON array. When an element contains both text and child elements, its text is stored under #text by default or under the chosen Text content key. CDATA is treated as regular text content.
Output Format and XML Declaration
Pretty (indented) uses 2 spaces, 4 spaces, or a tab. Compact (minified) removes formatting whitespace. These formatting choices are separate from Ignore XML declaration: leaving that checkbox unchecked includes parsed XML declaration metadata under ?xml when present, while checking it omits the metadata.
Input Encoding and XML Validation
Auto-detect reads the encoding from the XML declaration for input decoding. This is separate from whether declaration metadata appears in the output. To override decoding, choose UTF-8, UTF-16 LE, ISO-8859-1 (Latin-1), or Windows-1252. Malformed XML produces a readable validation error and may include line and column details.
Batch Conversion and Downloads
Add multiple XML files together. Each converted file has its own JSON output and download action. After successful conversions, Download all as ZIP becomes available.
Privacy and Practical Limits
Files are processed locally in your browser and are not uploaded to a server. Available device memory is the practical limit for processing. For very large generated JSON, the live preview shows the first 20,000 characters, while the downloaded file contains the full JSON.
Frequently Asked Questions
What happens to XML text content mixed with child elements?
When an element has both text and child elements (mixed content), the text is stored under a dedicated key - #text by default, or a key you choose - alongside the child elements.
Are CDATA sections supported?
Yes. CDATA content is treated the same as regular text content and included in the element's text or value.
What if an element repeats multiple times under the same parent?
Repeated sibling elements with the same tag name are automatically collected into a JSON array.
Is there a file size limit?
The practical limit is your device's memory. The live preview shows the first 20,000 characters of the generated JSON for very large documents, but the full JSON is still included in the downloaded file.
Can I convert multiple XML files at once?
Yes. Drop as many files as you like, convert them into separate JSON files, and download them individually or as a ZIP.