Skip to content

XML to JSON Converter

Convert XML to JSON in your browser using a clear convention: @ for attributes, #text for text and arrays for repeated elements. Unsafe DOCTYPE and entity declarations are refused, and you get a document tree plus pretty or minified JSON.

Text & Document Runs client-side Free to use
Jump to the tool
Share: X WhatsApp
Loading XML to JSON Converter…

About the XML to JSON Converter

XML to JSON Converter turns an XML document into JSON using a predictable, documented convention. The root element becomes the single top-level key; attributes become keys starting with @; an element that holds only text becomes a string; text alongside attributes or child elements is stored under #text; and child elements with the same name become an array in document order. Values are always kept as strings, so nothing is guessed.

The XML is checked before parsing: DOCTYPE declarations, entity declarations and processing instructions are refused, because they can expand entities or point at external files. Only the leading <?xml …?> declaration is accepted. The document is then parsed in memory by your browser’s XML parser and never inserted into the page. Namespaced names keep their prefix (such as dc:title) and namespace declarations are kept as @xmlns attributes; namespace URLs are never fetched.

How to use

  1. Paste XML or open an .xml file.
  2. Choose pretty-printed or minified JSON.
  3. Press Convert to JSON.
  4. Check the summary and document tree.
  5. Copy the JSON or download the .json file.

Key features

  • Documented @attribute, #text and repeated-element-as-array convention.
  • Rejects DOCTYPE, entity declarations and processing instructions.
  • Namespace prefixes and declarations kept, never fetched.
  • Line and column details for malformed XML.
  • Escaped document tree and element, attribute and depth counts.
  • Pretty (2 spaces, 4 spaces or tabs) or minified JSON.
  • Copy JSON and Download .json.

Best practices

  • Remove any DOCTYPE line before converting; it is not needed for conversion.
  • Expect a single element to be an object and repeated ones to be an array — handle both in your code.
  • Convert numbers and booleans in your own code, since all values stay strings.
  • Keep the original XML if comments or exact formatting matter.
  • Use the XML Formatter & Validator to tidy a document first.

Benefits

  • Predictable output that is easy to work with in code.
  • Safe handling of untrusted XML.
  • Quick inspection of a document’s structure.
  • Private: nothing is uploaded or stored.

Frequently asked questions

What convention does the converter use?

Attributes become keys starting with @ (for example "@id"), text that sits alongside attributes or child elements goes in "#text", an element with only text becomes a plain string, an empty element becomes "", and repeated sibling elements with the same name become an array.

Why is DOCTYPE rejected?

DOCTYPE and entity declarations can define entities that expand massively or reference external files. They are refused before parsing so these features cannot be used. Remove the DOCTYPE line and convert again.

How are namespaces handled?

Element and attribute names keep their prefix, such as dc:title, and declarations such as xmlns:dc are kept as "@xmlns:dc" attributes. The namespace URL is treated only as text and is never fetched.

Are numbers and true/false converted?

No. XML has no data types, so every value stays a string. This keeps leading zeros and long IDs exactly as they are.

What is lost in the conversion?

Comments, whitespace formatting, the exact interleaving of text and child elements in mixed content, and the order of differently named child elements may not be preserved. Converting back to XML may therefore not give the identical document.

What are CDATA sections turned into?

Their content is treated as ordinary text and appears in the string or #text value.

What are the limits?

Up to 5 MB of XML, 200,000 elements and 500 levels of nesting. The tree view shows the first 400 elements; the JSON contains the whole document.

Is my data uploaded or saved?

No. Pasted text and opened files are processed in your browser on your device. Nothing is uploaded, and data, settings and results are not saved in browser storage. Reset clears them from the page.