Skip to main content
Screendesk
Free tool

XML to JSON Converter

Convert XML to JSON and JSON to XML, with attributes, repeated elements, and parse errors handled. Everything runs in your browser.

Open source on GitHub

XML input

JSON output

JSON appears here as you paste XML.

Runs entirely in your browser. Nothing you paste here is uploaded or stored.

Conversion rules

How XML maps to JSON. The same rules apply in reverse for JSON to XML.

How XML constructs map to JSON
XMLExampleJSON
Element with text<name>Ada</name>"name": "Ada"
Attribute<user id="7">…</user>"user": { "@id": "7", … }
Text next to attributes<price currency="EUR">9.50</price>"price": { "@currency": "EUR", "#text": "9.50" }
Repeated elements<tag>a</tag><tag>b</tag>"tag": ["a", "b"]
Empty element<notes/>"notes": null
CDATA<![CDATA[a & b]]>Read as plain text: "a & b"
Comments, processing instructions<!-- note -->Dropped
Reference

XML vs JSON. Why the conversion needs conventions at all.

Differences between XML and JSON
TopicXMLJSON
RootExactly one root element is required.Any value can be the top level. JSON → XML wraps arrays and multi-key objects in the root element you name.
AttributesElements carry attributes and child elements.Only keys and values. Attributes use the @ prefix here.
OrderElement order is significant.Object key order is not guaranteed by the spec. Repeated elements keep their order inside an array.
TypesEverything is text unless a schema says otherwise.Strings, numbers, booleans, and null. Turn on “Convert numbers & booleans” to infer them.
NamesElement names cannot start with a digit or contain spaces.Any string is a valid key. Invalid characters become _ when converting to XML.
Escaping& < > " and ' must be escaped as entities.Only " \ and control characters are escaped.
FAQ

Frequently asked questions

How do I convert XML to JSON?

Paste XML or open an .xml file with XML → JSON selected. The XML is parsed by your browser’s built-in XML parser, and the JSON appears as you type. Attributes become keys starting with @, text that sits next to attributes or child elements goes in #text, and repeated elements with the same name become an array.

How do I convert JSON to XML?

Switch to JSON → XML and paste your JSON. Keys become element names, arrays become repeated elements, keys starting with @ become attributes, and a #text key becomes the element’s text. If the JSON has a single top-level key, it becomes the root element; otherwise the output is wrapped in the root element name you choose.

Why does my XML fail to parse?

XML must be well-formed: one root element, every tag closed and properly nested, attribute values in quotes, and & or < inside text escaped as &amp; and &lt;. The error message shows the browser’s description of the first problem, usually with a line and column.

Why are numbers strings in the JSON output?

XML has no data types, so every value is text by default. Turn on “Convert numbers & booleans” to turn values like 42, 9.50, and true into JSON numbers and booleans. Values with leading zeros and very long integers stay strings to avoid losing digits.

Is my XML uploaded anywhere?

No. Parsing and conversion happen in your browser, and downloads are created locally. Nothing is sent to a server.

Customer support runs on Screendesk.

Start for free