XML to JSON Converter
Convert XML to clean, pretty-printed JSON — or go the other way and turn JSON back into indented XML. Attributes, nested elements and repeated siblings are all preserved. Everything runs in your browser, so your data is never sent anywhere and nothing is stored.
How to use the XML ↔ JSON converter
- Choose a direction: XML → JSON or JSON → XML.
- Paste your document into the box, or click Load sample to see the mapping in action.
- Click Convert, then copy the pretty-printed result.
Mapping rules: element names become JSON keys, attributes are grouped under @attributes,
element text that sits alongside attributes goes under #text, and when a parent has two or
more child elements of the same name they become a JSON array. Converting back reverses
each of these rules.
More PAYATE tools
Frequently asked questions
What does this XML to JSON converter do?
It converts data both ways: paste XML to get a clean, pretty-printed JSON object, or paste JSON to build an indented XML document. Element names become object keys, attributes are grouped under @attributes, repeated sibling elements become JSON arrays, and the whole thing round-trips back the other way.
How are XML attributes handled in the JSON?
Attributes are collected into a child object under the @attributes key, so an element like <user id="7"> becomes { "@attributes": { "id": "7" } }. When an element has both attributes and text, the text is placed under a #text key so nothing is lost.
Why did my XML fail to parse?
The browser uses a strict XML parser, so the input must be well-formed: every tag closed, attributes quoted, and a single root element. A friendly message is shown if the parser finds an error — check for an unclosed tag, a stray & that should be &, or more than one top-level element.
Why did my JSON fail to parse?
JSON is also strict: keys and strings must use double quotes, there can be no trailing commas, and comments are not allowed. If conversion to XML fails, the message points at invalid JSON — paste it through a formatter first if you are unsure.
Is my data sent anywhere?
No. Both XML to JSON and JSON to XML run entirely in your browser using native DOMParser and JSON.parse — nothing is uploaded to a server and nothing is stored. It is safe for data you would not want to transmit.
Does it support Unicode and nested elements?
Yes. Deeply nested elements, mixed content and non-Latin text all convert correctly, and arrays are produced automatically whenever a parent has more than one child element of the same name.