OpenReplay Logo
12k

XML ⇄ JSON converter

Convert XML to JSON and back again — processed locally in your browser, with attributes, repeated elements, CDATA and mixed content handled for you.

Processed locally

About this tool

XML and JSON are the two dominant text formats for structured data, but they map to different shapes: XML carries elements, attributes, mixed text, and CDATA, while JSON has objects, arrays, and typed primitives. This converter parses XML with its own tokenizer (no DOMParser) and applies a predictable mapping — attributes become "@name" keys, pure-text elements become string values, repeated sibling elements collapse into arrays, and an element that carries both attributes or children and text keeps that text under a "#text" key. CDATA is read as text; comments and the XML declaration are dropped. JSON → XML runs the same rules in reverse, escaping text and attribute values and indenting with two spaces.

Use it to feed a legacy SOAP or RSS payload into a JSON-only API, to inspect a dense XML config as a navigable object tree, or to round-trip a document and confirm its structure survives. The "Auto-type values" option turns full-string matches like "42", "true", and "null" into real JSON numbers, booleans, and null so downstream code does not have to re-parse strings — toggle it off when you need every leaf to stay a string. In JSON → XML mode, set the root element name used when the JSON is not a single-key object.

Both conversions run entirely in your browser — no XML or JSON is ever uploaded to a server.

Frequently asked questions

How are XML attributes represented in the JSON output?

Each attribute becomes a key prefixed with "@" on the element's object — for example <book id="42"> becomes {"book": {"@id": 42}}. Converting JSON back to XML turns any "@"-prefixed key back into an attribute.

What happens to repeated XML elements and mixed text content?

Sibling elements that share a tag name are grouped into a JSON array. When an element has attributes or child elements as well as its own text, that text is stored under a "#text" key so nothing is lost.

Does the converter handle CDATA, comments, and the XML declaration?

CDATA sections are read as plain text and merged into the element's value. Comments and the <?xml ... ?> declaration are dropped, since neither carries data that maps cleanly to JSON.