JSON to XML Converter

Paste JSON and get well-formed XML. Choose the root element, how arrays are written and whether @attributes become real XML attributes. Invalid names and characters are fixed and reported, and your data stays in your browser.

JSON input

XML output

Your XML will appear here. Paste JSON on the left or press Load sample.

Options

How to convert JSON to XML

  1. Add your JSON. Paste it, drop a .json file onto the page, or press Load sample.
  2. Set the shape. Name the root element, choose whether arrays repeat the key or are wrapped in item elements, and decide if @ keys should become attributes.
  3. Copy or download. Copy the XML or save it as a .xml file. A note under the input lists anything that had to be adjusted.

The output updates as you type or change an option.

Before

{"user": {"@id": "7",
  "name": "Ava",
  "tags": ["a", "b"]}}

After

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <user id="7">
    <name>Ava</name>
    <tags>a</tags>
    <tags>b</tags>
  </user>
</root>

How JSON maps to XML

JSON and XML are not the same shape. XML needs exactly one root element, and it has no native array, number or null, so every converter has to make choices. These are the ones made here.

JSONXML outputNotes
ObjectChild elements named after the keysKey order is kept unless you sort
Array, Repeat modeThe key repeated once per itemThe default and the most common convention
Array, Wrap modeThe key containing one item element per entryThe item name is the option you set
Array in an arrayItem elements nested inside item elementsNeeded because XML cannot repeat an unnamed value
String, number, true or falseText inside the elementNumbers keep their written form
nullAn empty element such as <x/>XML has no null
Empty objectAn empty elementSame as null in the output
Empty array in Repeat modeNothing at allNo items means no elements; Wrap mode keeps the wrapper
Key starting with @An attribute on the parent elementOnly when the attributes option is on
Key #textText content of the parent elementLets an element have both attributes and text
Top-level value that is not an objectWrapped in the root elementThe root name is your option
&, <, > in textEscaped as entitiesQuotes are escaped inside attributes

Invalid names and characters

XML element names must start with a letter or an underscore and cannot contain spaces. A JSON key such as first name, 2nd or a/b is not a legal name. The converter replaces illegal characters with underscores, adds a leading underscore where a name starts with a digit, and keeps the original key in a key attribute so the information is not lost. Names that begin with xml, which the specification reserves, get a leading underscore, and colons are replaced because they are reserved for namespaces.

XML 1.0 also forbids most control characters, even when escaped. Any such character in a JSON string is replaced with U+FFFD, the replacement character, and a note under the input tells you how many were changed. Tabs, line feeds and carriage returns are kept.

When you need JSON to XML

Legacy and enterprise systems
SOAP services, older ERP and banking interfaces and many government feeds still expect XML. Convert a JSON payload to test them.
Config and data exchange
Build files, Android resources and sitemaps are XML. Convert generated JSON into the format the tool wants.
Feeds and imports
RSS, product feeds and some import tools read XML only. Turn a JSON export into something they accept.
Checking a mapping
Convert a sample, then compare it with the schema or XSD that your receiver provides. This tool does not validate against a schema.

What this converter does

Private by design
The conversion runs in your browser. Your JSON is not uploaded.
Always well-formed
The output is checked in tests against a strict XML parser on 1,500 random documents, including odd Unicode keys and values.
Nothing silently lost
Renamed keys, replaced characters and dropped empty arrays are reported in a note, and original key names are preserved in an attribute.
Exact numbers
Large IDs and numbers with trailing zeros are copied as written.
Exact error positions
Invalid JSON is reported with a line, a column and context, with an Auto-fix option for common mistakes.
Related tools
Tidy the JSON first with the JSON Formatter, or write YAML with JSON to YAML.

Frequently asked questions

How do I convert JSON to XML?

Paste the JSON or drop a .json file on the page. The XML appears straight away. Set the root element and array style if you need to, then press Copy or Download .xml.

Is my JSON uploaded to a server?

No. The conversion runs in your browser tab and nothing is sent anywhere.

Why is there a root element I did not write?

Well-formed XML has exactly one top-level element, and JSON has no such rule. The converter wraps your data in a root element. It is called root by default and you can rename it in the options.

How are arrays converted?

By default the key is repeated for each item, so a tags array of two strings gives two tags elements. The wrap option instead puts one item element inside a single tags element, with the item name you choose. Both are common, so pick the one your receiver expects.

How do I create XML attributes?

Start a key with @ and, with the attributes option on, it becomes an attribute of the parent element. A key named #text becomes the text of that element, so an element can have both attributes and text. Turn the option off to treat these as ordinary keys.

What happens to keys that are not valid XML names?

They are made legal by replacing bad characters with underscores and prefixing an underscore when a name starts with a digit. The original key is kept in a key attribute, and a note under the input says how many names were changed.

What happens to null and empty values?

null and empty objects become empty elements. An empty array becomes nothing in repeat mode, because there are no items to write, and an empty wrapper in wrap mode.

Can I convert XML back to JSON?

Not on this page. There is no single standard for it, so the result depends on conventions such as how attributes and repeated elements are treated.

Does it validate against an XSD or DTD?

No. It produces well-formed XML, which means it parses, but it cannot know the schema your receiver uses. Check the output against your schema with a validator.

Why was a character replaced?

XML 1.0 does not allow most control characters at all, even as entities. They are replaced with the Unicode replacement character and counted in the note under the input.