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
- Choose XML → JSON or JSON → XML.
- Paste your document in.
- For XML → JSON, decide how repeated elements should behave, and whether to strip namespace prefixes or keep comments.
- For JSON → XML, give the root element a name.
- Press Convert, then copy or download the result.
Examples
<book id="b1"><title>Dune</title></book> becomes {"book": {"@id": "b1", "title": "Dune"}}.Two
<book> elements always produce an array. With Always arrays, so does one — which keeps your parsing code honest.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?
<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?
What about XXE and other XML attacks?
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?
@ 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?
Can every JSON document become XML?
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.