ToolsForWeb

Saved

Tap ☆ on any tool to keep it here.

toolsforweb

XML / JSON Converter

Convert XML to JSON or JSON to XML, with attributes and text nodes preserved.

Runs in your browser — nothing is uploaded

Loading tool…

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

Pulling a value out of a SOAP or RSS response using JSON tooling instead of XPath.
Feeding legacy XML into a system that only accepts JSON.
Sketching an XML document by writing the easier-to-type JSON shape first.
Understanding how a given XML structure maps to keys and arrays.

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.

Related tools