Skip to main content

XML to JSON converter

Convert XML documents to JSON

No watermarkFree & unlimited
Mode
Input (XML)
Output (JSON)
All processing happens in your browser. No data is sent to any server.

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

Key facts about XML to JSON converter
ParserThe browser DOMParser in text/xml mode, so well-formedness rules are enforced exactly as a browser enforces them.
AttributesCollected into an @attributes object on the element, which keeps them separate from child element keys.
Text-only elementsCollapse to a plain string, so a tag containing just a name becomes a key and a string rather than a wrapper object.
Mixed contentText sitting alongside child elements is stored under a #text key on the same object.
Repeated siblingsTwo or more elements with the same tag name under one parent become a JSON array in document order.
CDATA sectionsSkipped by the walker, so text wrapped in CDATA does not appear in the output. Unwrap it before converting.
CommentsIgnored, along with processing instructions and the XML declaration itself.
NamespacesPrefixes are kept verbatim in keys, so a SOAP body arrives as soap:Body with no stripping option.
Empty elementsBecome an empty string, not null and not an empty object.
Error reportingA malformed document stops with the first 100 characters of the parser own error text.
Round tripNot lossless with the JSON to XML tool: @attributes comes back as an element named _attributes, not as attributes.
ModesPaste 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. 1

    Choose how to supply the XML

    Paste and convert is the default; switch to file upload for an .xml document on disk.

  2. 2

    Unwrap any CDATA

    Replace CDATA sections with escaped text first, because those nodes are skipped and their content would be lost.

  3. 3

    Convert

    The document is parsed and walked into a JSON tree, with the result shown in the output panel.

  4. 4

    Check the shape

    Look for @attributes and #text keys, and confirm repeated elements became arrays rather than single objects.

  5. 5

    Copy or download

    Copy the JSON to the clipboard, or save a .json file when you converted an uploaded document.

Specs & compatibility
Input and outputTakes .xml (application/xml) and returns the JSON as a blob with the application/json type, named after the file you dropped in.
EngineThe 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.
ModesBoth 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 capsTwenty XML files per run at 500 MB each; several JSON results are zipped in page memory as converted-json-files.zip.
Browser and deviceXML 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.
Every attribute on an element is placed in an object stored under the key @attributes on that element, with the attribute name as the key and its value as a string. Keeping them in their own container avoids collisions with child elements that happen to share a name, which is the usual failure of converters that merge the two. The prefix is fixed and cannot be changed here.
The most likely cause is a CDATA section. The walker handles element nodes and text nodes, and a CDATA node is neither, so its content is passed over silently. CDATA is commonly used to embed HTML inside feeds and configuration files, which is precisely where this bites. Replace the CDATA wrapper with properly escaped text and convert again.
Not during conversion. Keys come from the node names the parser reports, so an element declared as soap:Envelope stays soap:Envelope in the JSON. That is faithful to the document, but it does mean you have to use bracket notation to read those keys in JavaScript. A search and replace over the finished JSON is the simplest way to drop the prefixes if you prefer.
An array only when two or more siblings share a tag name under the same parent. A list with a single entry therefore produces an object, and the same document with two entries produces an array. This is inherent to converting XML without a schema, since nothing in the markup itself declares that an element is repeatable. Write consuming code that normalises both cases.
Not exactly. The JSON to XML tool on this site takes a generic object tree and writes elements from it, and its key sanitiser turns @attributes into an element named _attributes rather than restoring real attributes. Round-tripping therefore changes the document structure. Treat this conversion as a one-way transformation into a shape that is convenient for JavaScript.
The parse fails and the converter reports the first hundred characters of the error the browser produced, which usually names the line and the problem. Nothing partial is emitted, because a half-parsed tree would produce misleading JSON. Common culprits are unescaped ampersands, mismatched tags and an undeclared namespace prefix; fix those and the conversion completes.
View all

Need the opposite? Try JSON to XML

Updated

We use anonymous analytics to improve ToolChamp. No personal data is stored or sold. Privacy Policy