Skip to content
toolsdocks

Convert XML to JSON

Paste XML or open a file and get JSON as you type. This page opens the YAML and XML tool with XML selected and the To JSON action on; errors point to the line and column.

Runs on your device

More options in the full YAML and XML formatter and validator.

Loading tool…

How to convert XML to JSON

  1. Paste the XML or open an .xml file.
  2. Keep Language on XML and Action on To JSON.
  3. Read any error message, which names the line and column.
  4. 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

InputXML
OutputJSON
Enginejs-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.