How the conversion works
There's no universal standard for representing XML as JSON, so this tool uses a clear, consistent convention that's reversible in both directions:
- Attributes: become keys prefixed with
@, like "@id": "1".
- Text mixed with attributes: when an element has attributes and also direct text, the text goes into the
"#text" key.
- Simple elements: an element with only text and no attributes becomes a plain string, not an object.
- Repeated elements: two or more sibling elements with the same name become an array; a single element becomes a plain object.
- Multiple root keys in JSON: since XML requires a single root element, the tool automatically wraps multiple top-level keys in a
<root> element when converting to XML.
Converting back and forth
When you switch the conversion direction (XML → JSON or JSON → XML), if there's already a valid result on screen, it's automatically reused as the new input — handy for checking that a conversion round-trips cleanly, or for continuing to edit in the other format.
Frequently asked questions
How are XML attributes represented in JSON?
Each attribute becomes a key prefixed with "@" in the JSON object. For example, <book id="1"> becomes {"@id": "1", ...}, alongside the other keys for child elements.
What is the "#text" key that shows up in the generated JSON?
It appears when an XML element has both attributes and direct text (not just child elements). Since text can't sit loose in a JSON object alongside other keys, it's stored under the "#text" key.
How are repeated XML elements (with the same name) handled?
When an element has two or more direct children with the same tag name, they're grouped into an array in the JSON. If there's only one child with that name, it becomes a plain object, not a one-item array.
What happens if the JSON has more than one root key when converting to XML?
Since an XML document can only have a single root element, when the JSON has multiple top-level keys, the tool automatically wraps them all in a <root> element.
Is the pasted content sent to a server?
No. All conversion happens locally in your browser, in JavaScript, without sending the content off your device.