XML ↔ JSON Converter

Convert XML to JSON and JSON back to XML, with the array behaviour made explicit instead of guessed — entirely in your browser.

🔒 Runs entirely in your browser — nothing you type is uploaded or stored on a server.

This tool converts XML into JSON and JSON into XML, using the XML parser already built into your browser. There is no library to download and no server involved — nothing you paste leaves the page.

Also on Txtset: convert a YAML file instead · pull the words out of HTML.

The interesting part of any XML-to-JSON converter is what happens to repeated elements, and most tools hide it. One <item> naturally maps to an object; two map to an array — so the same schema produces a different shape depending on the data, and code that reads the output breaks on the day a list happens to have one entry. Rather than silently picking a rule, this page makes it a setting: arrays only when repeated (the default, matching most converters) or always arrays (predictable, and what you want if a program will consume the result).

The rest of the mapping is conventional and stated here so nothing is a surprise: attributes are prefixed with @, mixed text content lands in #text, CDATA sections are unwrapped into ordinary text, and comments are dropped unless you ask to keep them. Namespace prefixes are preserved as written, with a toggle to strip them.

Going from JSON to XML, keys become element names, @ keys become attributes, and everything is escaped properly. Because not every JSON key is a legal XML name — 2 items is not — illegal names are rewritten to a legal form and the page tells you it did that. It will not hand you invalid XML.

How to use

  1. Choose XML → JSON or JSON → XML.
  2. Paste your document in.
  3. For XML → JSON, decide how repeated elements should behave, and whether to strip namespace prefixes or keep comments.
  4. For JSON → XML, give the root element a name.
  5. Press Convert, then copy or download the result.

Examples

Attributes
<book id="b1"><title>Dune</title></book> becomes {"book": {"@id": "b1", "title": "Dune"}}.
The array question
Two <book> elements always produce an array. With Always arrays, so does one — which keeps your parsing code honest.
An illegal key
JSON key 2 items cannot be an XML element name, so it is written as _2_items and you are told.

Frequently asked questions

Why do repeated elements sometimes become an array and sometimes not?
Because XML has no way to say “this is a list of one”. Converters infer it from the data, so one <item> looks like an object and two look like an array. Set Always arrays if a program will read the output — then the shape stays the same no matter how many entries there are.
Is my XML sent to a server?
No. The conversion uses your browser's own XML parser, so the document never leaves this tab. There is no library download either — this page needs no network at all after it loads.
What about XXE and other XML attacks?
The browser's DOMParser does not resolve external entities, so the classic XXE attack — making a parser fetch a URL or read a local file — is not reachable here. The one that is reachable is internal entity expansion (“billion laughs”), so documents declaring an unusual number of internal entities are refused, and input is capped at 2 MB.
How are attributes and text represented?
Attributes get an @ prefix, so id="b1" becomes "@id": "b1". When an element has both attributes and text, the text lands in #text. CDATA is unwrapped into ordinary text.
What if my XML is malformed?
You get the browser parser's own message, which usually names the line. Note that a malformed document does not raise an error in the browser — it returns a document containing an error element — which is why some converters appear to succeed and hand you nonsense.
Can every JSON document become XML?
Almost. XML element names cannot start with a digit or contain spaces, so keys like 2 items are rewritten to a legal form and flagged. XML also has no arrays, so a JSON array becomes repeated elements of the same name.