Convert XML to JSON or JSON to XML instantly. Handles attributes, arrays, and deeply nested structures.
XML and JSON are two ways to describe the same structured data — XML uses nested tags with optional attributes, while JSON uses nested objects, arrays, and key-value pairs. This converter translates between them in both directions, mapping XML attributes to an @attributes key, text content to #text, and repeated tags to JSON arrays, then pretty-printing the result with two-space indentation.
It handles deeply nested elements, mixed content, and self-closing tags, and reports a clear error if the input is malformed. People use it to:
Everything runs local and in-browser using the built-in DOMParser — nothing is uploaded to a server, so even sensitive payloads stay entirely on your device.
XML describes data with nested tags and optional attributes, and was designed to be both human and machine readable with strict markup rules. JSON describes the same data with lightweight objects, arrays, strings, and numbers, and is native to JavaScript. JSON is usually more compact, while XML can carry attributes and namespaces that JSON has no direct equivalent for.
Attributes on an element are grouped under an @attributes key on that element's JSON object, and any text content is stored under a #text key when the element also has attributes or child elements. If an element has only text and nothing else, it becomes a plain string. This convention preserves the original XML structure so it can be rebuilt later.
Yes. By default the left pane takes XML and the right pane shows JSON. Click the swap button (⇄) between the panes to reverse the flow and convert JSON back into XML, including @attributes and #text keys back into real attributes and text.
When a parent contains several child elements that share the same tag name, the converter collects them into a JSON array — so <book> repeated three times becomes a three-element array. Going the other way, a JSON array is expanded back into repeated XML elements with the same tag name.
The converter validates as you type. If the XML is malformed or the JSON cannot be parsed, a red error message appears below the input pane describing the problem, and the output pane is cleared until you fix it. This makes it easy to spot a missing closing tag or a stray comma.
JSON output is pretty-printed with two-space indentation so nested structures are easy to read. When converting to XML, the output is also indented two spaces per level and prefixed with a standard <?xml version="1.0" encoding="UTF-8"?> declaration.
No. Parsing uses the browser's built-in DOMParser and runs entirely on your device. Your XML and JSON never leave the page, which makes the tool safe to use with private or sensitive data and even works offline once loaded.