Skip to content
cliplimeClipLime

Convert JSON to XML

Paste JSON or drop a file and get well formed XML, with the root, attributes and lists under your control.

Runs on your device, nothing is uploaded

Convert from

to

Paste, type, drop a file here or load one.

0 characters, 0 lines

Options

XML attributes

Keys that start with this become attributes.

Indentation

More options

Starts the file with <?xml version="1.0"?>.

At a glance

Input
JSON text or a .json file: an object, a list of records or a single value. Errors are shown with their line and column.
Root
An object with exactly one key, whose value is not a list, uses that key as the root element. Anything else is wrapped in a root element called root, which you can rename.
Lists
A list inside an object becomes repeated elements named after its key. A list at the top becomes repeated item elements, and you can rename them.
Attributes
Keys that start with @ become attributes, and #text holds the text of an element that also has attributes.
Names
Keys that are not valid XML names, such as first name or 2022, are repaired with underscores, and a note says so.
Layout
Indent with 2 or 4 spaces or a tab, or write everything on one line, with or without the XML declaration.
Privacy
Your JSON is converted in your browser tab and never uploaded.

How to do it

  1. 1

    Add your JSON

    Paste it, drop a .json file on the input box, or press Load a file. Example fills in a small list of people with nested values.

  2. 2

    Name the root and the items

    Under Options, set the Root element name and the Name of each row element. The root name is used when the data does not have exactly one key at the top, and the row name for the items of a list.

  3. 3

    Choose attributes and layout

    Keep XML attributes on @name so keys that start with @ become attributes, or pick name to make everything an element. Choose the indentation, and the XML declaration under More options.

  4. 4

    Copy or download

    Press Copy, or Download for an .xml file. The notes under the result list any names that were repaired.

How JSON objects, lists and values become XML

JSON and XML are both trees, but they name things differently. In JSON a value belongs to a key. In XML a value is the text of an element, and every element needs a name and a parent. These rules fill the gaps.

  • An object becomes an element and each key a child element: for {"name": "Ana", "age": 31} the children are <name>Ana</name> and <age>31</age>.
  • XML needs exactly one root element. If the object has a single key and its value is not a list, that key is the root. Otherwise everything is wrapped in <root>, so {"name": "Ana", "tags": ["a", "b"]} gives <root><name>Ana</name><tags>a</tags><tags>b</tags></root>.
  • A list inside an object is written as the same element repeated, named after the key. That is how XML spells a list.
  • A list at the top, such as an API response with many records, becomes <root><item>...</item><item>...</item></root>. A list inside another list has no key to name its items, so those are called item as well.
  • Numbers and booleans are written as text, and both null and an empty string become an empty element.

Attributes, text and namespaces

JSON has no attributes, so the converter uses a convention: a key that starts with @ becomes an attribute of its parent element, and #text holds the text of an element that also has attributes. {"book": {"@id": "bk101", "title": "XML Guide", "price": {"@currency": "EUR", "#text": 12.5}}} becomes <book id="bk101"><title>XML Guide</title><price currency="EUR">12.5</price></book>.

It is the same convention the XML to JSON page uses, so XML you converted to JSON can be turned back. Namespaces work in the same way: a key "@xmlns": "http://www.sitemaps.org/schemas/sitemap/0.9" on the root comes out as an xmlns attribute, so a sitemap's <urlset xmlns="..."> can be written exactly. The converter does not add a DOCTYPE or a schema reference, so add those by hand if the target system needs them.

Pick name instead of @name under XML attributes to turn the convention off. Every key then becomes an element, and a key such as @id is written as _id.

What XML cannot keep, and what to check

  • Types. XML holds only text, so the number 12.5 and the string "12.5" produce the same element. A program reading the XML decides what each value means.
  • Null and empty text. Both become an empty element such as <zip/>, and cannot be told apart when the XML is read back.
  • Empty lists. XML has no way to write a list with no items, so the element is left out and a note says how many.
  • Names. XML names must start with a letter or an underscore and cannot contain spaces. first name becomes first_name, 2022 becomes _2022 and a/b becomes a_b. A warning gives an example.
  • Special characters. & and < are escaped, and so are quotes (&quot; and &apos;), which is valid even if it looks busy. A tab or line break inside an attribute value and a carriage return in text are written as character references (&#9;, &#10; and &#13;), because an XML reader would otherwise turn them into spaces or plain line feeds. Control characters that XML forbids are removed, with a warning.
  • Large numbers. JSON numbers with more than 15 digits can be rounded when read, and a note warns you. Put such IDs in quotes in the JSON to keep every digit.

Keys are written in the order they appear in the JSON, which matters for formats that expect elements in a fixed order.

Where XML is still required

Most new web services use JSON, but XML is still what SOAP services, RSS and Atom feeds, sitemaps, Maven and Android configuration files and many industry and government exchange formats expect. Those formats usually add rules about element order, namespaces and required attributes. This page converts the structure only, so check the result against the schema or documentation of the system that will read it.

Questions people ask

How do I write an attribute instead of an element?

Start the key with @. In {"book": {"@id": "bk101", "title": "XML Guide"}} the @id key becomes the attribute id of the book element, and title becomes a child element. A key called #text holds the text of an element that also has attributes.

Why is my XML wrapped in a root element?

XML allows only one top level element. If your JSON is a list, or an object with several keys, the converter adds a root element called root. Change its name under Root element name. An object with exactly one key, whose value is not a list, uses that key as the root instead.

Can I rename the item elements of a list?

Yes, for a list at the top, change Name of each row element. For a list inside an object the name of its key is used, so "book": [...] gives repeated book elements.

What happens to null, true and numbers?

XML has only text, so numbers and booleans are written as their text, such as 12.5 or true. Null becomes an empty element, the same as an empty string. A program reading the XML has to know which elements are numbers.

Why did some of my key names change?

XML names cannot contain spaces or most punctuation and cannot start with a digit. The converter replaces such characters with underscores, and adds an underscore in front of a name that starts with a digit. A warning shows one example.

Is my JSON uploaded?

No. The JSON is read and converted in your browser tab, so private data stays on your device.