XML ↔ JSON Converter
Convert
A bidirectional XML/JSON converter that preserves what most converters lose: attributes, mixed content, repeated elements. Attributes become keys prefixed with `@` (configurable), so `<book id="1">` becomes `{"@id": "1"}`. Repeated child elements collapse into arrays. Text content alongside attributes goes into a `#text` key (also configurable). The XML side uses the browser's native `DOMParser` — same code path your browser uses for `application/xml` responses, so namespaces, entities, and CDATA all work. The JSON side reverses the same conventions for round-tripping.
How to use
- Pick the direction. Drop in XML (or JSON) — sample data is one click away.
- Tune the attribute prefix and text key if you're targeting a specific schema (`x2js`, `fast-xml-parser`, custom).
- JSON→XML lets you set a root element name and toggle the `<?xml ... ?>` declaration. Copy when ready.
Frequently asked questions
- Why prefix attributes?
- Because JSON doesn't natively distinguish attributes from child elements. Prefixing (with `@`, `_`, or anything you like) makes the round-trip lossless — you can convert XML→JSON→XML and get the same document back. Without the convention, attributes would collide with child element names.
- Does it handle mixed content (`<p>hello <b>world</b>!</p>`)?
- Partially. Pure text becomes a string; element children with text become `{ #text: '...' }` alongside the children. Interleaved text and elements (like `hello <b>world</b>!`) collapse to the joined text in the `#text` key, which round-trips but loses the original ordering. For documents with heavy mixed content (HTML, DocBook), a dedicated parser is better.
Related tools
CSS Unit Converter
Convert between px, rem, em, pt, vw, vh, and % using your own base font size and viewport.
JSON ↔ YAML Converter
Convert JSON to YAML or YAML to JSON — pick the indent and copy the result.
Data Size Converter
Convert between bytes, KB, MB, GB, TB — in decimal (1000) or binary (1024).
Roman Numeral Converter
Convert between Arabic numbers and Roman numerals from 1 to 3999.
Number Base Converter
Convert numbers between binary, octal, decimal, and hexadecimal.
Unit Converter
Convert length, weight, temperature, area, volume, speed, and time.