XML to JSON converter
Convert XML documents to JSON
The document is handed to DOMParser, the XML parser already built into your browser, so validation is as strict as any real XML tool: one unclosed tag and the conversion stops with the parser own message. From the resulting tree a short walker builds the JSON. Attributes are grouped under an @attributes key, an element whose only content is text becomes a plain string, mixed content puts its text under #text, and sibling elements sharing a tag name are gathered into an array. The output is printed with two-space indentation.
Key facts about XML to JSON converter
| Parser | The browser DOMParser in text/xml mode, so well-formedness rules are enforced exactly as a browser enforces them. |
|---|---|
| Attributes | Collected into an @attributes object on the element, which keeps them separate from child element keys. |
| Text-only elements | Collapse to a plain string, so a tag containing just a name becomes a key and a string rather than a wrapper object. |
| Mixed content | Text sitting alongside child elements is stored under a #text key on the same object. |
| Repeated siblings | Two or more elements with the same tag name under one parent become a JSON array in document order. |
| CDATA sections | Skipped by the walker, so text wrapped in CDATA does not appear in the output. Unwrap it before converting. |
| Comments | Ignored, along with processing instructions and the XML declaration itself. |
| Namespaces | Prefixes are kept verbatim in keys, so a SOAP body arrives as soap:Body with no stripping option. |
| Empty elements | Become an empty string, not null and not an empty object. |
| Error reporting | A malformed document stops with the first 100 characters of the parser own error text. |
| Round trip | Not lossless with the JSON to XML tool: @attributes comes back as an element named _attributes, not as attributes. |
| Modes | Paste and convert, or file upload for an .xml file, with copy on the output and a character count on both panels. |
What happens to your file
Nothing about the document is transmitted. Pasted markup stays in the input panel, and an uploaded .xml file is read with the File API and parsed by the DOMParser that is part of your browser, on your own device. The walker that builds the JSON and the serialisation step both run in this tab. No entity is resolved over the network and no schema is fetched, so a document referencing an external DTD simply converts without it. Nothing is stored after you reset the tool.
About this tool
- 1
Choose how to supply the XML
Paste and convert is the default; switch to file upload for an .xml document on disk.
- 2
Unwrap any CDATA
Replace CDATA sections with escaped text first, because those nodes are skipped and their content would be lost.
- 3
Convert
The document is parsed and walked into a JSON tree, with the result shown in the output panel.
- 4
Check the shape
Look for @attributes and #text keys, and confirm repeated elements became arrays rather than single objects.
- 5
Copy or download
Copy the JSON to the clipboard, or save a .json file when you converted an uploaded document.
| Input and output | Takes .xml (application/xml) and returns the JSON as a blob with the application/json type, named after the file you dropped in. |
|---|---|
| Engine | The browser's own DOMParser reads the XML in text/xml mode and a recursive walk turns the element tree into the JSON object - nothing is fetched to do it. |
| Modes | Both modes: paste the XML in and copy the JSON straight back out, or hand over a file and take the JSON as a download. |
| Batch and caps | Twenty XML files per run at 500 MB each; several JSON results are zipped in page memory as converted-json-files.zip. |
| Browser and device | XML to JSON needs only the File API, a Blob download and the parser already in the bundle, so every current browser behaves the same and the page keeps working with the network off. |
- Feed the converter a short representative sample first. The shape depends on your document, and seeing where @attributes and #text land saves guesswork later in code.
- Beware the single-child case: if a list has exactly one entry, it becomes an object rather than an array, so consuming code should handle both shapes.
- Namespace prefixes remain in the keys, which means bracket notation in JavaScript. Strip the prefixes with a search and replace over the output if the colons are inconvenient.
- Content inside CDATA disappears, so check any document that carries embedded HTML or script blocks, since those are exactly where CDATA is used.
- For very large feeds, upload the file rather than pasting; the parser handles it either way, but a multi-megabyte paste makes the editor sluggish.
- Turn a SOAP response or a legacy API payload into JSON so it can be consumed by modern JavaScript without an XML library.
- Convert an RSS or Atom feed into JSON for a front-end that has no parser of its own.
- Inspect a configuration or export file in a shape that is easier to read and diff than angle brackets.
Related tools
View allNeed the opposite? Try JSON to XML
Works well with this4
Other JSON tools12
Updated