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 & 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.
