# XML to JSON

Convert XML to JSON with attributes, namespaces and repeated elements handled properly. Broken XML gets a line and column. Nothing is uploaded.

Canonical page: https://filetity.com/xml-to-json

## Capabilities

- Free: Yes, with no watermark and no page limit.
- Account required: No. There is no account system.
- Processed on device: Yes. The file is read by your browser and never uploaded. There is no server to send it to.
- Formats: XML in, including namespaces, attributes, CDATA, comments and a DOCTYPE. JSON out, indented.
- Limits: No size limit beyond what your browser will hold in a text box. Comments, the XML declaration and the DOCTYPE are dropped, because JSON has nowhere to put them.
- Mobile: Yes, on any modern mobile browser. Large files are limited by the memory the phone gives the browser.
- Offline: Yes, once the page has loaded. The tool keeps working with no network connection.

## Questions

### Why does one item come out as a value and two as a list?

Because XML has no way to say a list of one. A document with a single record looks structurally identical to one that never repeats, so every converter has to guess, and code written against a two-record export then breaks on a one-record one. This page lets you name the elements that should always be a list, which removes the guess.

### What happens to attributes?

They become keys prefixed with @, so an id attribute is "@id". The prefix is not decoration: XML names cannot start with @ or #, so a prefixed key can never collide with a child element of the same name, which is the failure mode of converters that merge the two together.

### Are numbers converted to numbers?

Not unless you ask. XML has no types, so every value is text, and turning "007123" into 7123 or a long account number into a rounded float destroys real data. Turn on the detection when you know the document is safe for it; it only converts a value that survives a round trip back to exactly the same characters.

### Does it handle namespaces like soap: and atom:?

Yes, and the prefix is kept as part of the key, so soap:Envelope stays soap:Envelope and the xmlns declaration is kept as an attribute. Resolving prefixes to their full URIs has no agreed representation in JSON, and keeping what the author wrote is the only form that can be written back out unchanged.

### What do I get when the XML is broken?

The line and the column where parsing stopped, and a sentence about what was expected there. A stray less-than sign in text, a closing tag that does not match its opening one and an unclosed element each get a different message, which is the difference between finding it in ten seconds and reading the whole document.

## Related tools

- [JSON to XML](https://filetity.com/json-to-xml): Convert JSON to indented XML, with attributes and arrays handled.
- [XML formatter](https://filetity.com/xml-formatter): Format, beautify and validate XML, with real error positions.
