Quick answer: paste XML on the left and the JSON appears instantly. Elements become keys, attributes land under _attributes, text under _text, repeated elements become arrays. Flip the toggle and the same engine converts JSON back to XML. It's powered by xml-js 1.6.11 (36 KB, runs in this tab) — a 254-byte catalog XML comes out as 710 bytes of pretty JSON and converts back byte-for-byte.

Convert

XML input0 bytes
Drop an .xml or .json file, or click to open
Ad
JSON output0 bytes

Ready. Nothing you paste leaves this page.
Ad

How xml-js Maps XML to JSON

XML constructExampleJSON (compact mode)
Element<book>…</book>"book": { … }
Attribute<book id="bk101">"_attributes": {"id": "bk101"}
Text content<price>44.95</price>"price": {"_text": "44.95"}
Repeated elementstwo <book> siblings"book": [{…},{…}] (array)
Declaration<?xml version="1.0"?>"_declaration": {…}
Comment<!-- note -->"_comment": "note"
CDATA<![CDATA[raw]]>"_cdata": "raw"
Processing instruction<?php echo 1;?>"_instruction": {…}

Verbose mode keeps the document as an elements tree with type, name, and attributes fields on every node — closer to the DOM, handier for walking, heavier to read. Compact mode is what most APIs and fixtures want. The underscore prefix on reserved keys is configurable if your downstream schema forbids it.

How the Converter Works

The page runs xml-js 1.6.11 (MIT), the same engine widely used for config and fixture conversion, bundled to 36 KB with its sax parser and loaded from this site. Parsing happens in your tab: XML goes in through xml2js, JSON comes out through serialization; the reverse direction parses JSON first and rebuilds markup with json2xml. Both directions run on every keystroke, and errors surface as messages instead of silent empty output.

A worked example, measured

Take a 254-byte catalog with two books, each carrying an id attribute, an author, a title, and a priced element with a unit attribute:

That round-trip property is why this pairing is safe for round-tripping fixture data: convert, store as JSON, regenerate the XML when a legacy consumer needs it. It's also the honest answer on size — JSON repeats key names and wraps attributes and text, so element-heavy XML roughly triples in bytes going to pretty JSON. Attribute-heavy XML shrinks instead.

What converts, and what to watch

Credits and licenses

Conversion by xml-js 1.6.11 (MIT) with the sax 1.6.1 parser (BlueOak-1.0.0), bundled under /vendor/ with license texts. Nothing executes outside your browser tab.

Frequently Asked Questions

How do I convert XML to JSON online?

Paste your XML and the converter parses it into a DOM tree, then walks elements, attributes, and text nodes to build the equivalent JSON, all locally in your browser. Attribute names are typically prefixed (commonly with @) to keep them distinct from child elements. Malformed XML is rejected with a parser error before any output is produced.

What gets lost when converting XML to JSON?

Mixed content — elements interleaved with free text — maps awkwardly because JSON has no way to express 'text between children' naturally. Also lost are the distinction between attributes and elements, comment nodes, processing instructions, and sibling-element order guarantees in some converters. Purely data-style XML round-trips cleanly; document-style XML does not.

Can the converter go back from JSON to XML?

Yes, this is a two-way converter, so you can round-trip in either direction. Expect cosmetic differences on the way back, such as attribute prefixing and whitespace, even when the data itself survives. Two-way conversion is handy for inspecting SOAP or config payloads in whichever format you find easier to read.