AZ Tools

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

  1. Pick the direction. Drop in XML (or JSON) — sample data is one click away.
  2. Tune the attribute prefix and text key if you're targeting a specific schema (`x2js`, `fast-xml-parser`, custom).
  3. 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