XML to JSON Converter
Convert XML to JSON with attributes as @-keys and arrays for repeated elements.
Written by Golam Rabbani, Founder & Lead Engineer
How to use this xml to json converter
- Paste your XML document into the input box.
- Press Convert to parse the XML and emit a JSON tree.
- Read the structured output, with attributes mapped to @-prefixed keys.
- Copy the JSON or hit Reset to clear and try a new document.
About this xml to json converter
The XML-to-JSON converter walks your XML, builds a parse tree, then maps it to a JSON object using a small, predictable convention: each element becomes a key, repeated sibling elements become an array, and attributes become keys prefixed with @ so they sit alongside the children without colliding. Text content inside an element with attributes or child elements lands under a "#text" key. Comments and processing instructions are skipped because JSON has no equivalent representation. Entities like &, <, and numeric character references decode back to their original characters.
Because the converter runs in your browser there is no upload step. That matters for SOAP responses, SAML assertions, and other XML payloads that often contain identifiers or session data you should not send to a third party. The output shape is deterministic, so it is safe to pipe into downstream code, JSON Schema validation, or jq queries.
For example, the input <book id="1"><title>Dune</title><author>Herbert</author></book> becomes: { "book": { "@id": "1", "title": "Dune", "author": "Herbert" } }
FAQ
- How are XML attributes represented?
- Each attribute becomes a key prefixed with @ on the element's JSON object. That keeps attributes separate from child elements while staying valid JSON.
- What about repeated child elements?
- If two or more sibling elements share a tag name, they collapse into a JSON array under that tag. A single child stays a single object so the output is not unnecessarily wrapped.
- Are CDATA sections preserved?
- Yes. CDATA contents are read as plain text and become part of the surrounding element's text node.
- What happens to XML comments and processing instructions?
- They are dropped because JSON has no canonical place for them. If you need to keep them, format the XML first and process the JSON separately.
- Is my XML uploaded?
- No. Parsing and conversion happen entirely in your browser.
- Why did conversion fail with "Mismatched closing tag"?
- The parser saw a closing tag that did not match the most recently opened element. Run the XML through the XML Formatter first to find the unbalanced tag and fix it.