CraftTools

XML ⇄ JSON Converter

Guide: JSON vs YAML vs XML vs CSV: Choosing a Data Format

Nothing you enter or choose here leaves your device. This tool runs in your browser.

A round trip

Take the same order in XML and in JSON. The XML first:

<order id="7"><item sku="A1">Pen</item><item sku="B2">Ink</item><total>9.5</total></order>

Converted to JSON, it becomes:

{
  "order": {
    "@id": 7,
    "item": [
      { "@sku": "A1", "#text": "Pen" },
      { "@sku": "B2", "#text": "Ink" }
    ],
    "total": 9.5
  }
}

Convert that JSON back and you get the original XML, with the two items repeated and the attributes restored. JSON doesn't have attributes, so they're written as keys that start with a prefix, which is the @ sign by default. Text that sits next to attributes goes in a key called #text. You can change both names.

The rules in one table

XMLJSON
An attribute id="7"A key with the prefix: "@id": 7
Text beside attributesA #text key
An element that repeatsAn array
An element that appears onceA single value
An empty elementnull
Namespace declarationsDropped

Where conversions surprise people

  • One item or a list? A single item becomes a plain value, and two become an array. A program reading the JSON must cope with both, or you should add a second item to your sample so the shape is consistent.
  • Order. JSON objects have no guaranteed key order, while XML cares about the order of elements. A document where order matters, such as a book's chapters, needs care.
  • Mixed content. Text with tags in the middle, like a paragraph with bold words, doesn't fit well in JSON.
  • Numbers. By default 42 becomes a number and true a boolean. Turn off type detection to keep everything as text, which protects values like 007.
  • Invalid names. JSON keys can contain spaces, but XML element names can't. Going from JSON to XML, odd keys are cleaned up.

JSON to XML

Any valid JSON works. If the JSON has one top-level key, that key becomes the root element. Otherwise, the root name you choose is used. Arrays turn into repeated elements, and keys with the attribute prefix become attributes.

A checklist for a big conversion

  1. Convert a small sample first and inspect it.
  2. Look for single-versus-list cases and add examples so they're consistent.
  3. Decide whether numbers should stay text.
  4. Check that the result opens in whatever consumes it.

Everything runs in your browser. To turn the structure into code, use XML to DTO or JSON to DTO, and tidy the output with the JSON formatter or the HTML and XML formatter.

Written by Akinrinmade Michael · Updated October 24, 2026

How to use

  1. 1Choose XML to JSON or JSON to XML.
  2. 2Paste your data into the input box.
  3. 3Set the attribute prefix and other options if you need to.
  4. 4Click Copy output, or use the output as the next input.

Frequently asked questions

How are XML attributes shown in JSON?

Attributes become keys that start with a prefix, @ by default, such as "@id": 42. Text next to attributes or child elements goes in a "#text" key. Both names can be changed.

How does it decide what is a list?

An element that appears more than once under the same parent becomes a JSON array. A single element becomes a single value, so add a second one to your sample if you expect a list.

Does JSON to XML work with any JSON?

Yes. If the JSON has one top-level key it becomes the root element, otherwise your chosen root name is used. Keys that aren't valid XML names are cleaned up, and arrays turn into repeated elements.

Is my data uploaded?

No. The conversion runs in your browser and nothing is sent to a server.

Read the guides

Learn how this works and how to get the most from it.

Developer

JSON vs YAML vs XML vs CSV: Choosing a Data Format

The strengths and weaknesses of JSON, YAML, XML and CSV, with simple advice on which to use for APIs, config files and spreadsheets.

3 min read

Developer

Turn JSON or XML Into Classes (DTOs) in Java, C# and More

What a DTO is, how generated classes map JSON and XML, and the details to check before you trust a generated model.

3 min read

XML to DTO Generator

Turn XML into Java (JAXB), C#, TypeScript, Kotlin, Python or Go classes.

JSON Formatter & Validator

Prettify, minify and validate JSON, with error line numbers.

YAML ⇄ JSON Converter

Convert YAML to JSON and JSON to YAML with error line numbers.

CSV ⇄ JSON Converter

Convert CSV to JSON and JSON to CSV, with any delimiter.