MergeJSON

How to Convert JSON to XML: Attributes, Arrays & Clean Markup

Convert JSON to XML the right way — map keys to attributes vs elements, name the root and array items, and keep it private. Online, in Python, and in JavaScript.

Published June 14, 2026

XML still runs enterprise systems, SOAP services, RSS feeds, and countless legacy integrations — so turning JSON into XML is a recurring need. The catch is that JSON and XML don’t map one-to-one: XML has attributes and a single root, JSON has neither. This guide shows how to convert JSON to XML and produce clean, well-formed markup.

The quickest way: convert JSON to XML online

Copy your JSON, paste it into the JSON to XML converter, and press Convert to XML. You get indented, well-formed XML you can copy or download.

One thing to watch: some popular converters default to publicly sharing your input through a generated link — a real privacy risk for configuration or business data. Prefer a client-side tool (ours runs entirely in your browser), which never uploads or shares your data and has no size cap.

Use it when: you want a fast, private conversion on any device.

The mismatch you have to resolve

XML can express things JSON can’t, so you have to make a few decisions:

  • The root. XML needs exactly one root element; JSON can be an array or a bare value. You choose the root name.
  • Attributes vs elements. XML values can live in attributes (<book id="1">) or child elements (<id>1</id>). JSON has no attributes, so a converter needs a convention.
  • Arrays. XML has no array type; repetition is expressed by repeating an element.

A good tool surfaces these instead of guessing.

Control attributes with the @ convention

The widely used convention — and the one our tool follows — is to prefix attribute keys with @ and put text content under #text:

{ "book": { "@id": 1, "@lang": "en", "#text": "Working with JSON" } }

becomes:

<book id="1" lang="en">Working with JSON</book>

Keys without the prefix become child elements. This gives you real control over the shape of the output rather than forcing every value into an element.

How arrays become repeated elements

Because XML has no arrays, each item is emitted as a repeated element. A tags array:

{ "tags": ["json", "xml"] }

becomes repeated <tags> elements:

<tags>json</tags>
<tags>xml</tags>

At the top level, a bare JSON array is wrapped in the root with a configurable item element name (default item).

Convert JSON to XML in Python

dicttoxml handles the common cases:

from dicttoxml import dicttoxml

xml = dicttoxml({"book": {"title": "Working with JSON"}}, attr_type=False)
print(xml.decode())

For full control over attributes and structure, build the tree with the standard library’s xml.etree.ElementTree and set elem.set("id", "1") for attributes.

Convert JSON to XML in JavaScript

In Node, a library like fast-xml-parser goes both directions:

import { XMLBuilder } from "fast-xml-parser";

const builder = new XMLBuilder({ format: true, attributeNamePrefix: "@", ignoreAttributes: false });
const xml = builder.build({ book: { "@id": 1, title: "Working with JSON" } });

Match the builder’s attributeNamePrefix to the convention your data uses.

Which method should you use?

For a quick, private conversion — especially when you want attribute control and clean output — use the online JSON to XML converter: paste, set the root and attribute options, and download. Use Python or a Node library when the conversion is part of a service. Either way, decide up front which values are attributes and which are elements.

Need the reverse? See how to convert XML to JSON. Comparing formats? Read JSON vs XML vs YAML.

Ready to merge your JSON?

Combine files or snippets in your browser — free and private.

Open the merge tool

Keep reading