Convert JSON to XML

Generate well-formed XML from JSON, with a declaration, one root element and element names made safe automatically.

Drop your file here, or browse

Images, documents, spreadsheets, data files and subtitles. Your file stays on your device.

Your file is converted on this device and is never uploaded to a server.

Producing valid XML from JSON

Plenty of systems still require XML: payment gateways, government portals, e-invoicing standards, feeds and older enterprise software. Converting JSON to XML sounds simple, but XML has rules JSON does not: a single root element, names that cannot start with a digit or contain spaces, and a clear distinction between attributes and child elements.

This converter handles those rules for you. It adds an XML declaration, wraps the data in a root element when needed, repeats elements for arrays, turns keys that start with @ into attributes and cleans up names that XML would reject.

JSON vs XML at a glance

Main differences between the JSON and XML formats
FeatureJSONXML
Full nameJavaScript Object NotationExtensible Markup Language
TypeHierarchical dataHierarchical markup data
IntroducedEarly 2000s (RFC 4627 in 2006)1998
Created byDouglas Crockford; now ECMA-404 and RFC 8259W3C
StructureNested objects and arraysNested elements with attributes
CommentsNoYes, with <!-- -->
Data typesString, number, boolean, null, object, arrayText, unless an XSD schema defines types
Best forAPIs, web apps and app settingsEnterprise data exchange, feeds and office files
SupportEvery programming languageEvery language; common in enterprise systems
MIME typeapplication/jsonapplication/xml

How to convert JSON to XML

  1. Step 1: Choose a JSON file

    Drop a .json file onto the converter.

  2. Step 2: XML is preselected

    Leave the target set to XML.

  3. Step 3: Convert

    The JSON is mapped to elements and attributes and pretty-printed with two-space indentation.

  4. Step 4: Download the XML

    Save the file and validate it against your schema if the receiving system has one.

Conversion rules

Single root guaranteed

An object with one top-level key uses it as the root; anything else is wrapped in <root>.

Arrays repeat elements

{"tag": ["a", "b"]} becomes two <tag> elements.

Attributes from @ keys

{"@id": 5} becomes id="5" on the parent element.

Safe names

Invalid characters become underscores and names starting with a digit get a leading underscore.

When JSON to XML is needed

  • Integrations with XML APIs. Prepare request bodies for SOAP or XML-based services.

  • Feeds and sitemaps. Generate XML structures from JSON data.

  • E-invoicing and filings. Draft XML that you then align with the required schema.

  • Legacy imports. Feed data to software that only reads XML.

How the root element is chosen

If your JSON is an object with exactly one key, such as { "catalog": { ... } }, that key becomes the root element. If the object has several top-level keys, or its only value is an array, everything is wrapped in a <root> element so the document stays valid.

A top-level array becomes <root> containing one <item> element per entry. Rename root and item in your editor if your target system expects different names.

  • { "catalog": {...} } gives <catalog> as root.
  • { "a": 1, "b": 2 } gives <root><a>1</a><b>2</b></root>.
  • [ {...}, {...} ] gives <root><item>...</item></root>.

Round-tripping with XML to JSON

The @ prefix for attributes and #text for element text match what the XML to JSON converter produces, so you can convert XML to JSON, edit the data and convert it back.

Null values become empty self-closing elements. Special characters such as & and < in values are escaped automatically, so the output parses cleanly.

Tips for JSON to XML

  • Use a single top-level key named after the root element your system expects.
  • Mark attributes with @ in your JSON before converting.
  • Validate the output against the XSD if one is provided.
  • Avoid arrays of arrays; XML has no natural way to express them.

JSON to XML questions

Does the output include an XML declaration?

Yes: <?xml version="1.0" encoding="UTF-8"?> is added at the top.

How do I create attributes?

Prefix the key with @, for example { "book": { "@id": "42", "title": "Dune" } }.

What happens with arrays?

Each item becomes a repeated element with the array's key as its name.

What if a key is not a valid XML name?

Invalid characters are replaced with underscores, and names starting with a digit get an underscore prefix.

Is the XML indented?

Yes, with two spaces per level for readability.

Is my JSON uploaded?

No. The XML is generated in your browser.

Related conversions