---
title: "XML to JSON Converter With Attributes Kept | ToolSugar"
description: "Convert XML to JSON in your browser. The XML is validated first, attributes get an @_ prefix and repeated elements become arrays. Nothing is uploaded."
canonical: https://toolsugar.com/tools/xml-to-json
image: https://toolsugar.com/og.png
---

# XML to JSON

This tool converts XML to JSON in your browser using fast-xml-parser. It validates the XML first and reports the line and column of any problem. Attributes become keys with an @\_ prefix, elements that repeat under one parent become an array, and all values stay strings. Nothing is uploaded.

Runs on your device

## How it works

1. Paste XML into the XML box, or open a .xml file.
2. Read the JSON on the right and the mapping rules above the box.
3. If the XML is invalid, fix the line and column in the red message.
4. Press Copy or Download to save data.json.

## Key facts

- **Where it runs**: In your browser tab. The text and files you use are never uploaded.
- **Live result**: The output updates as you type or paste, with no button to press.
- **Attributes**: Keys with an @\_ prefix, for example id="1" becomes "@\_id": "1".
- **Repeated elements**: Siblings with the same name become a JSON array. A single one stays a plain value.
- **Text with attributes**: The text of an element that also has attributes is stored under the key "#text".

## Common uses

- Reading a SOAP response or an RSS feed as plain JSON.
- Moving an old XML export into a JSON based system.
- Checking whether an XML file is well formed.

## Questions

### Is my data sent to a server?

No. The conversion runs in your browser with JavaScript, so what you paste or open stays on your device. You can switch off your network after the page loads and it keeps working.

### Why is a single item not an array?

JSON has no schema to say a field repeats, so one element becomes an object and two or more become an array. Handle both shapes in your code if the count can vary.

### Are numbers converted?

No. Every value stays a string, so 007 and 1.50 are kept exactly as written.

### Does it keep the XML declaration or comments?

The XML declaration is dropped. Comments are ignored. Element and attribute names and values are kept.

[Read the XML to JSON guide](https://toolsugar.com/blog/how-to-convert-xml-to-json)

## Related tools

- [JSON to YAML](https://toolsugar.com/tools/json-to-yaml)
- [YAML to JSON](https://toolsugar.com/tools/yaml-to-json)
- [JSON Formatter](https://toolsugar.com/tools/json-formatter)
- [HTML to Markdown](https://toolsugar.com/tools/html-to-markdown)
