How to convert XML to JSON
- Paste the XML or open an .xml file.
- Keep Language on XML and Action on To JSON.
- Read any error message, which names the line and column.
- Copy the JSON or download converted.json.
Worked example
<r version="2"><item id="a">One</item><item id="b">0012</item></r> becomes {"r":{"@_version":"2","item":[{"@_id":"a","#text":"One"},{"@_id":"b","#text":"0012"}]}}.
Formats and limits
| Input | XML |
|---|---|
| Output | JSON |
| Engine | js-yaml (YAML 1.2) and fast-xml-parser with validator |
Limitations
- Text mixed between child elements keeps its words but not its position between them; a warning says so.
- Comments and processing instructions are not part of the JSON.
- Files up to 50 MB.
Questions
How are XML attributes shown in JSON?
Attributes become keys starting with @_, and an element's text next to attributes goes under #text, so <price currency="USD">44.95</price> becomes {"@_currency":"USD","#text":"44.95"}.
Are numbers converted?
No. Values stay text, so 0012 keeps its leading zeros and nothing is rounded.
Can I convert JSON back to XML?
Yes. With XML selected, choose the From JSON action; the @_ and #text keys turn back into attributes and text.
Privacy
Runs on your device. Files and text are processed in this browser tab and are not uploaded.
This page opens the YAML and XML formatter and validator ready for this task. See the privacy policy for how toolsdocks handles data.