XML ↔ JSON Converter
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
JS Object ↔ JSON
Convert a JavaScript object literal (`{name: 'Alice'}`) to strict JSON — or strict JSON back into a tidy JS literal with unquoted keys.
String Escape Converter
Escape a string for 10 contexts at once — JavaScript, JSON, HTML entities, URL, SQL, regex, Bash (single/double quote), C string, Unicode \u escapes. Copy whichever you need.
Plist Viewer (binary & XML)
Open an Apple property list — binary or XML — and read it as a tree, or convert it to JSON or XML plist.
JSON ↔ YAML Converter
Convert JSON to YAML or YAML to JSON — pick the indent and copy the result.
INI ↔ JSON Converter
Round-trip between INI-style config files and JSON — supports sections, dotted nesting, comments, and value type inference.
TOML ↔ JSON Converter
Convert between TOML (`Cargo.toml`, `pyproject.toml`, Hugo configs) and JSON — handles tables, array-of-tables, inline tables, typed scalars.