deftools.io Developer Tools

JSON ↔ XML Converter

Convert JSON to XML and XML to JSON online. Supports attributes, arrays, namespaces, and custom root elements.

0 chars
0 chars

About this tool

The JSON ↔ XML Converter translates between JSON and XML in both directions. Paste JSON on the left to get formatted XML on the right, or paste XML to get a JSON object back. Everything updates live as you type.

Example JSON input — an object with a name field and a roles array — produces XML with <name>Alice</name> and repeated <roles> elements. In the reverse direction, XML elements with the same tag name are automatically collected into a JSON array, and XML attributes become @-prefixed keys (e.g., type="home" becomes "@type": "home").

Keys starting with @ in your JSON are rendered as XML attributes, so a JSON object with an @version key produces an element with a version attribute. Toggle the attribute and text-content options to match the convention your system expects. Choose 2-space, 4-space, tab, or minified output.

FAQ

How are XML attributes handled?

By default, XML attributes like type="home" become JSON keys prefixed with @, such as "@type": "home". In the JSON → XML direction, keys that start with @ are rendered back as attributes. Turn off "Use @-prefixed keys as attributes" if you want a simpler convention where everything is an element.

What happens with repeated XML elements?

When XML → JSON encounters multiple child elements with the same tag name (e.g., two <roles> elements), they are collected into a JSON array: "roles": ["admin", "user"]. A single element becomes a scalar value. In the JSON → XML direction, arrays produce repeated elements.

How are numbers and booleans converted?

In XML → JSON, text values that look like integers, decimals, true, false, or null are automatically coerced to their JSON types. In JSON → XML, these types are serialized to their string representation. Quoted values in JSON are kept as text.

Can I set a custom root element name?

Yes. The "Root element" field (default: "root") sets the name of the wrapping element when converting a JSON object to XML. This only applies to JSON → XML; XML → JSON preserves whatever root element your XML uses.

How is this different from the XML Formatter tool?

The XML Formatter tool focuses on formatting, validating, and inspecting XML with a tree view and statistics — XML to JSON conversion is one of its modes. This tool is a dedicated bidirectional converter with extra options like custom root elements and @-prefixed attribute handling.

More developer tools

Copied!