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
JSON output0 bytes

Ready. Nothing you paste leaves this page.
Advertisement

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?

Paste XML into the left pane and the JSON appears instantly — every element becomes an object key, attributes land under _attributes, and text content under _text. The conversion runs on the xml-js engine inside your browser tab, so nothing uploads. Click Copy or Download to save the JSON. The direction toggle also converts JSON back to XML.

How are XML attributes represented in JSON?

With the default compact mapping, an attribute like id="bk101" becomes "_attributes":{"id":"bk101"} inside the element's object, and text content becomes a "_text" key. The underscore prefix keeps attributes from colliding with child element names. The declaration, comments, CDATA, and processing instructions get their own reserved keys (_declaration, _comment, _cdata, _instruction).

Can JSON be converted back to XML?

Yes. This tool is two-way: flip the direction toggle, paste JSON, and the same engine rebuilds XML. Round trips are byte-exact when the spacing matches the original — a 254-byte catalog XML converted to JSON and back reproduces the original byte-for-byte, which makes the pair safe for config files and fixture data.

What happens to repeated XML elements?

Repeated siblings become a JSON array. Two <book> elements inside a <catalog> produce "book":[{...},{...}] — one element is an object, two or more become an array of objects. That's the main structural gotcha when writing consuming code: an XML feed can flip a field between object and array depending on how many entries it has that day.

Is my XML uploaded to a server?

No. The converter (xml-js 1.6.11, 36 KB) ships with this page and parses in your tab. Nothing is transmitted, which matters for API responses, SAML assertions, config files with credentials, and any XML you would not paste into someone else's converter.

Why does my JSON get bigger than the XML?

JSON repeats the key names for every element and adds the _attributes and _text wrappers, so it usually grows. A 254-byte XML catalog becomes 710 bytes of pretty-printed JSON — nearly 3x. Minified JSON (no spaces) and shorter key options shrink it, but expect JSON to be larger for element-heavy documents and smaller for attribute-heavy ones.

Advertisement