Tools / JSON ↔ XML Converter

JSON ↔ XML Converter.

Convert JSON to XML and XML back to JSON, with attributes, repeated elements and CDATA handled.

Runs in your browser

Used when the JSON has several top-level keys or is an array. Leave empty to reuse a single top-level key.

JSON keys starting with this prefix become XML attributes, and attributes come back with it.

Key for element text when the element also has attributes or children.

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result

About JSON ↔ XML Converter

The JSON ↔ XML Converter turns a JSON document into well-formed XML and parses XML back into JSON, using the common "attribute prefix" convention so the mapping is predictable in both directions. Keys that start with @ become attributes, a #text key holds the text of an element that also has attributes or children, arrays become repeated sibling elements with the same name, and null becomes an empty element such as <price/>. For example, {"book": [{"@id": "b1", "title": "Dune"}]} produces <book id="b1"><title>Dune</title></book>. Going the other way, repeated child elements are collected into an array, attributes come back with the prefix, CDATA sections and character references are decoded, and comments, processing instructions and the XML declaration are skipped. By default every value stays a string, because XML has no types; switch on number and boolean conversion when you want "9.99" to become 9.99. Typical mistakes the converter catches are mismatched closing tags, a bare & that should be &amp;, unquoted attribute values and documents with more than one root element; each error shows the line and column. JSON keys that are not valid XML names, such as "first name" or "1st", are made safe by replacing invalid characters with underscores. A single element whose children repeat only once comes back as an object, not a one-item array, so check the shape if your code expects a list. Everything runs locally in your browser, so API payloads and feeds never leave your machine.

How to Use

  1. Paste JSON or XML into the input and pick the direction.
  2. Adjust the root element, attribute prefix, text key or indentation if needed.
  3. Copy or download the converted result.

Frequently Asked Questions

How are XML attributes represented in JSON?

As keys with the attribute prefix, "@" by default, so <book id="b1"> becomes {"book": {"@id": "b1"}}. You can change the prefix, or set it empty to treat every key as an element.

Why is a repeated element sometimes an object and sometimes an array?

XML has no array type. An element that appears several times under the same parent becomes an array; an element that appears once becomes a single value. Normalize the shape in your code if it must always be a list.

Are numbers converted automatically?

Not by default, because XML text is untyped and values such as ZIP codes with leading zeros would be damaged. Turn on number and boolean conversion to get 9.99 and true instead of strings.

Is my data uploaded?

No. The conversion runs in your browser and the page makes no network request while you use it.

Related Tools