Developer Tools

XML to JSON Converter

Convert XML to JSON in your browser: paste XML or upload a .xml file and get live JSON with your choice of attribute style, text key, root unwrap, type inference, indent and namespace handling, plus exact line and column errors. 100% private, nothing is uploaded.

Conversion options

Your JSON will appear here.

How does XML map to JSON?

Every element becomes a JSON object or a plain string when it only holds text. Attributes become @name keys by default, or a single @attributes object when you pick the grouped style. Text content goes under the #text key, which you can rename, and when an element has both text and child elements, the text stays under that key next to the children. Repeated sibling elements become an array, so three <book> elements turn into one book array with three entries. CDATA sections become plain text, even when they contain markup-like characters. Comments and processing instructions are checked for well-formedness but never appear in the JSON, and values stay strings unless type inference is on, in which case 29.99 becomes a number and true becomes a boolean. Note that 007 stays a string, because a leading zero means the value is a code, not a number.

🛡️ XXE safety: DOCTYPE declarations are refused. They are the only place external entities can be defined, so a file that tries to load local files or remote URLs through entities is rejected before parsing.

🔒 Privacy: parsing and conversion run locally in your browser. Your XML is never uploaded, stored or seen by anyone else.

More developer tools

How this calculator works

Converting XML to JSON means turning a tree of elements into nested objects. Each element becomes a JSON object, or a plain string when it only holds text. Attributes become @name keys, text content goes under the #text key, and repeated sibling elements become an array, so three <book> elements turn into one book array with three entries. CDATA sections become plain text even when they contain markup-like characters, entity references like &amp; are decoded back to their characters, and comments are checked for well-formedness but never appear in the JSON, because JSON has no comment syntax to hold them.

Every converter makes these mapping choices for you, and this one lets you make them yourself. Pick the attribute style: @name keys next to the element data, or a single grouped @attributes object. Rename the text key if your API expects something other than #text. Unwrap the root element when you only need its contents, turn on type inference so 29.99 becomes a number and true becomes a boolean (values stay strings by default, and 007 stays a string either way, because a leading zero means the value is a code, not a number), and keep or strip namespace prefixes like ns: in element and attribute names. You can also pick 2-space, 4-space or minified JSON output. When the XML is malformed, the error names the exact line and column plus what went wrong, so a mismatched closing tag or a bare & is a one-minute fix.

Everything runs in your browser: paste XML or upload a .xml or .txt file, copy the JSON or download it as a .json file, and your data never leaves your device. DOCTYPE declarations are refused outright for XXE safety, since they are the only place external entities can be defined. If your XML needs cleaning up first, format it with the XML Formatter, and when you need to go the other way, the JSON to XML Converter takes JSON back to XML with the same @name and #text conventions. The JSON Formatter pretty-prints the result, and the YAML to JSON Converter handles the same job for YAML config files.

Frequently asked questions

How do I convert XML to JSON online?
Paste your XML into the input box, or upload a .xml or .txt file. The JSON appears live as you type. Copy it or download it as a .json file. Nothing is uploaded: parsing and conversion run in your browser.
How are XML attributes converted to JSON?
By default each attribute becomes a key with an @ prefix, so <book id="bk101"> becomes { "@id": "bk101" }. If you prefer, switch the attribute style to grouped and all attributes land in one @attributes object instead: { "@attributes": { "id": "bk101" } }.
What happens to repeated XML elements?
Repeated sibling elements become a JSON array. Three <book> elements under one <catalog> become a single book key holding an array with three entries, in document order. A single element stays a plain object or string, so the JSON only uses arrays where the XML actually repeats.
Why are my numbers still strings in the JSON?
Values stay strings by default, because XML itself has no number or boolean type, and guessing wrongly can corrupt data such as zip codes or product codes. Turn on type inference and 29.99 becomes a number and true becomes a boolean. Values with a leading zero, such as 007, always stay strings, because the zero means the value is a code, not a number.
What happens to XML comments and CDATA sections?
Comments and processing instructions are checked for well-formedness but never appear in the JSON, because JSON has no comment syntax to hold them. CDATA sections become plain text, so a description wrapped in CDATA keeps its content verbatim, even when it contains characters that look like markup.
Why does this tool refuse DOCTYPE declarations?
DOCTYPE is the only place external entities can be defined, and a crafted file can use them to make a parser read local files or fetch remote URLs, an attack called XXE. This tool rejects any DOCTYPE before parsing starts, so a malicious file is never processed. Remove the DOCTYPE and the rest of the document converts normally.
Disclaimer: Results are estimates for planning purposes only and are not financial advice. Actual loan terms, taxes and investment returns vary. Consult a qualified professional before making financial decisions.