Skip to content

JSON to XML Converter

Turn a JSON document into well-formed XML with control over the root element, attributes and formatting.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is JSON to XML Converter?

Going from JSON to XML requires conventions too. Here object keys become elements, arrays become repeated elements with the same name, keys starting with a prefix (default @_) become attributes and a key such as #text holds the text of an element that also has attributes.

If your JSON has a single top-level key it becomes the root element; otherwise (arrays, scalars, several keys) the content is wrapped in the root name you choose. Text and attribute values are escaped, invalid XML characters are removed, and keys that are not legal XML names (spaces, leading digits) are renamed with underscores and reported, or rejected if you disable that fix. Big integers are written digit for digit.

How does it work?

  1. Paste your JSON.
  2. Set the root element name, attribute prefix and text node name if you need something other than the defaults.
  3. Choose the indentation, whether to add the XML declaration and whether empty elements should be self-closing.
  4. Copy or download the XML, or Swap to convert it back.

Common use cases

  • Sending JSON data to a SOAP or legacy service that expects XML.
  • Generating XML config fixtures from JSON test data.
  • Producing RSS-like or sitemap-like XML from structured data.
  • Round-tripping with XML to JSON to check a conversion.

Examples

Try this input in the tool above:

Input
{"catalog":{"@_lang":"en","book":[{"@_id":"bk101","title":"XML Developer's Guide","price":{"@_currency":"USD","#text":44.95}},{"@_id":"bk102","title":"Midnight Rain","price":{"@_currency":"USD","#text":5.95}}]}}
Output
<?xml version="1.0" encoding="UTF-8"?>
<catalog lang="en">
  <book id="bk101">
    <title>XML Developer&apos;s Guide</title>
    <price currency="USD">44.95</price>
  </book>
  <book id="bk102">
    <title>Midnight Rain</title>
    <price currency="USD">5.95</price>
  </book>
</catalog>

Privacy

JSON to XML Converter runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

JSON has no attributes, comments or namespaces, so those come only from your naming conventions. Arrays of arrays are wrapped in <item> elements because XML has no direct equivalent.

Frequently asked questions

How do I create attributes?

Prefix the key with @_ (or your chosen prefix): {"book":{"@_id":"1","title":"XML"}} becomes <book id="1"><title>XML</title></book>. Use #text for text next to attributes.

What happens when the JSON is an array?

XML needs a single root, so the array is wrapped: [1,2] becomes <root><item>1</item><item>2</item></root> with your root name.

What if a key is not a valid XML name?

By default it is renamed (first name becomes first_name) and listed in a warning. Disable the fix option if you prefer an error.

More tools in JSON & Data →