XML to JSON
Paste XML and get JSON in this tab with fast-xml-parser (MIT). Elements become object keys. Attributes become keys that start with @, and #text is character data. DOCTYPE declarations and DTD entities are not processed. Nothing is uploaded.
XML
JSON
How to use XML to JSON
- Paste or open XMLType, paste, or open a .xml file. The limit is 1 MB of UTF-8 text.
- Choose JSON optionsPick an indent of 2 or 4 spaces, or compact JSON.
- Copy or downloadCopy the JSON or download output.json. If the XML is invalid or contains a DOCTYPE declaration, an error is shown instead.
Limits and how it works
- The input is limited to 1 MB of UTF-8 text, including files you open. The document may have at most 64 levels and 100,000 nodes.
- The XML must be well-formed and have one root element. Comments and processing instructions are ignored. The XML declaration is not included in the JSON.
- DOCTYPE declarations and DTD or external entities are rejected. This converter does not expand custom entities and does not load files or URLs named in a DTD.
- Element or attribute names that would be unsafe as JSON keys (__proto__, prototype, or constructor) are rejected.
How XML becomes JSON
This page converts XML to JSON with fast-xml-parser 5.12.1 (MIT). It does not format existing XML; use XML Formatter for that. To go the other way, use JSON to XML.
A well-formed document with one root element becomes a JSON object with that element as the only top-level key. Repeated sibling elements become a JSON array. An attribute such as id is written as @id. When an element has both attributes and text, the text is stored as #text. Values stay strings; the converter does not guess numbers or booleans.
The five predefined XML entities (&, <, >, ", and ') and numeric character references are decoded. DOCTYPE declarations, DTD entity expansion, and external entities (XXE) are not processed, so a document that includes a DOCTYPE is rejected. The MIT license notice is kept at /notices/fast-xml-parser-5.12.1.txt.
Frequently asked questions
Is my text or file uploaded?
No. Everything runs in your browser tab with JavaScript. Nothing you type, paste or drop is sent to a server, logged or stored by ALink Tools.
Is this the same as XML Formatter?
No. XML Formatter pretty-prints or minifies XML you already have. This page reads XML and writes a new JSON document.
Why was a DOCTYPE rejected?
A DOCTYPE can define entities, including external ones (XXE) or recursively expanding ones. This converter does not process DOCTYPE declarations or entities, so it rejects those documents instead of expanding them.
How are attributes represented?
An attribute is a key that starts with @, such as @id. If the same element also has text, that text is stored under #text.
Can I convert JSON back to XML here?
No. This page only writes JSON from XML. JSON to XML is a separate converter.
Related tools
All toolsJSON to XML Converter
Convert JSON to well-formed XML in your browser with fast-xml-parser.
XML Formatter
Pretty-print or minify XML in your browser, without sending it to a server.
JSON Formatter & Validator
Format, minify, sort keys, and catch syntax errors cleanly.
YAML to JSON
Convert YAML to JSON in your browser with js-yaml. Read multiple documents in one file and get an error for duplicate keys.