XML to JSON Converter
Paste XML to get JSON, or switch the direction and paste JSON to get XML. Attributes become keys with a prefix, repeated elements become arrays, and text, CDATA, comments, entities and the XML declaration are handled. If the XML is not well formed, you get the problem with its line and column. You can choose the attribute prefix, turn numbers and true or false into real JSON values, trim spaces and set the indent. Everything runs in your browser.
Attributes become keys with the prefix (@id), text next to attributes or child elements becomes #text, repeated elements become an array and an empty element becomes an empty string. Because JSON has one key per element name, the order of children with different names, and text mixed in between them, is not kept. Custom entities declared in a DOCTYPE are not supported, and nothing you paste is uploaded: everything runs in your browser.
Related Tools
[6 suggestions]XML Formatter and Validator
Format, minify and validate XML. Errors show the line and column, and the text inside your elements is never changed.
Developer & WebJSON Formatter
Validate, pretty-print, and minify JSON with clear error reporting for invalid input.
Developer & WebJSON to YAML Converter
Convert JSON data into clean, readable YAML configurations instantly with customizable formatting.
Format ConversionYAML to JSON Converter
Convert YAML configurations and documents into pretty-printed, valid JSON in real time with syntax validation.
Format ConversionJSON to CSV Converter
Convert a JSON array of objects into downloadable CSV with automatic headers.
Developer & WebHTML Entity Encoder / Decoder
Escape text as HTML entities, or turn named and numeric entities back into characters.
Format ConversionAbout the XML to JSON Converter
XML and JSON hold the same kinds of data in different shapes, so a converter needs a convention. This one follows the common one. Each element becomes a key named after it. An element with only text becomes a string. Attributes become keys that start with a prefix, @ by default, so id="7" is "@id": "7". If an element has text and also attributes or child elements, its text goes under the key #text. Elements with the same name next to each other become an array, and an empty element becomes an empty string, or null if you choose. With the typed option, text that is exactly true, false or a plain number such as 42 or -3.5 becomes a JSON boolean or number, while values such as 007, 1.50 and very long ids stay text so nothing is changed. The XML reader is strict, like a real XML parser: one root element, matching tags, quoted attributes, no repeated attribute, and only the entities lt, gt, amp, quot and apos plus number references. Comments, processing instructions and a doctype are skipped, CDATA is kept as text, and entities declared in a doctype are refused. Errors show the line and the column. Going from JSON to XML, keys with the prefix become attributes, the text key becomes the text, arrays become repeated elements, and the text is escaped. A JSON object with one key uses it as the root, and anything else is wrapped in a root element whose name you can choose. Keys must be valid XML names. One limit: because JSON has one key per element name, the order of children with different names, and text mixed between them, is not kept. Everything runs in your browser and nothing you paste is uploaded.
How do I convert XML to JSON?▾
Paste the XML into the box and the JSON appears below. Attributes become keys with the prefix, repeated elements become arrays, and the text of an element becomes its value. Copy the result with the button.
How are attributes and text handled?▾
Attributes become keys that start with a prefix, @ by default, such as "@id". If an element has both text and attributes or child elements, the text is stored under "#text". You can change the prefix in the options.
Why is my XML rejected?▾
The tool reads XML strictly. Common causes are a missing or mismatched closing tag, an unquoted attribute value, a stray & that is not written as &, two root elements, or an entity such as that XML does not define. The message shows the line and the column.
Will the order of elements be kept?▾
Not between different names. JSON has one key per element name, so children with different names are grouped by name and text mixed between them is joined. Repeated elements with the same name keep their order in an array.
Can I convert JSON back to XML?▾
Yes, use the other direction. Keys with the prefix become attributes, #text becomes text, and arrays become repeated elements. Names must be valid XML names, and a JSON array inside an array cannot be written.
Is my data uploaded?▾
No. The conversion runs in your browser, and what you paste is not sent anywhere or stored.