XML / JSON Converter
Convert XML to JSON or JSON to XML, with attributes and text nodes preserved.
Results are provided as is, for general information. Check anything important before relying on it. See the Terms of Use.
About this tool
Converts an XML document to JSON and back. Attributes become keys prefixed with @_, an element's text content lands under a #text key when the element also has attributes or children, and repeated sibling elements are folded into a JSON array. The same conventions run in reverse, so a JSON object in that shape rebuilds the XML. This is the pragmatic mapping most XML-to-JSON libraries use — it is not a lossless representation: XML comments are dropped, and the distinction between an attribute and a child element only survives because of the @_ prefix. Parse errors on either side report the line and column. Conversion happens entirely in your browser.
When to use it
Questions
Why do some keys start with @_?
That prefix marks what was an XML attribute, so <book id="1"> becomes {"book":{"@_id":1}}. It keeps attributes distinct from child elements, which would otherwise collide — an element and an attribute can share a name. When converting JSON back to XML, keys with the @_ prefix are written as attributes.
What happens to repeated elements?
Two or more sibling elements with the same tag name become a JSON array. A single occurrence stays a plain object or value. This means a document with one <item> and a document with several produce different shapes — code that consumes the JSON has to handle both, or you normalize it yourself.
Is the conversion lossless?
No. Comments are dropped, insignificant whitespace is not preserved, and the order between attributes and children is not represented. Round-tripping XML through JSON and back gives you equivalent data, not a byte-identical document.
Why did my JSON fail to convert to XML?
The JSON root must be an object with a single top-level key that names the root element. A bare array, a string, or an object with several top-level element keys has no single root and is rejected.