Convert XML to JSON and back — two-way, byte-exact round trips, no upload
_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.
| XML construct | Example | JSON (compact mode) |
|---|---|---|
| Element | <book>…</book> | "book": { … } |
| Attribute | <book id="bk101"> | "_attributes": {"id": "bk101"} |
| Text content | <price>44.95</price> | "price": {"_text": "44.95"} |
| Repeated elements | two <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.
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.
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.
ns:tag becomes the key "ns:tag") — readable, but not split into namespace + local name.< in XML unescapes into JSON strings, and re-escapes on the way back.<book> is an object, two are an array. If your consumer needs stability, normalize arrays downstream.nativeType option exists for the brave.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.
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.
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).
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.
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.
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.
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.