Convert JSON to XML!

Input JSON to convert it into XML! For SOAP and legacy integrations.
JSON
Result
 

Convert JSON to XML!

Turn a JSON object into an indented XML document. Keys starting with @ become attributes, a #text key becomes the element's text, and arrays repeat an element with the same name, so plain JSON is enough to describe XML that has attributes.

It fits situations where you hold data as JSON but must send XML: a SOAP request body, an RSS feed or sitemap, or a legacy payment, logistics or government API that only accepts XML.

How to use

  1. Paste JSON into the JSON box. Make the top level an object with a single key, like {"rootName": {...}}, and that key becomes the root element.
  2. Where you need attributes, add keys prefixed with @ such as "@id": "1"; to combine attributes with text content, use a "#text" key.
  3. Review the document under Result, including the <?xml ...?> declaration, and copy it.

Example

Input (JSON)
{
  "rss": {
    "@version": "2.0",
    "channel": {
      "title": "Release notes",
      "item": [
        { "title": "v1.2 & fixes", "guid": { "@isPermaLink": "false", "#text": "r-12" } },
        { "title": "v1.3", "guid": { "@isPermaLink": "false", "#text": "r-13" } }
      ]
    }
  }
}
Output (XML)
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Release notes</title>
    <item>
      <title>v1.2 &amp; fixes</title>
      <guid isPermaLink="false">r-12</guid>
    </item>
    <item>
      <title>v1.3</title>
      <guid isPermaLink="false">r-13</guid>
    </item>
  </channel>
</rss>

@version and @isPermaLink became attributes, and the #text of guid became the element's content. The item array is written as two <item> elements, and the & in the title is escaped to &amp;.

Supported features

  • Adds the <?xml version="1.0" encoding="UTF-8"?> declaration and indents with two spaces.
  • A single-key top-level object uses that key as the root; multiple keys or a top-level array are wrapped in <root>, with each array entry written as <item>.
  • Escapes &, <, >, " and ' as entities.
  • Characters not allowed in XML names (spaces and so on) become _, and keys starting with a digit get a leading _: first name → first_name, 2nd → _2nd.
  • null values are written as empty elements like <tag/>.
  • Uses the same mapping as the XML to JSON tool, so data can go back and forth between the two without changing shape.

Use cases

Building a SOAP request body

Hand-writing tags from a WSDL sample makes it easy to mismatch an opening and closing tag. Write the request data as JSON, convert it, and tag pairs and escaping come out right.

Prototyping an RSS feed or sitemap

Sketch the feed your server should produce as JSON, check which keys turn into attributes and which into repeated elements, then port that shape to code.

Notes and limitations

  • An empty array ([]) has nothing to repeat and disappears from the output.
  • Numbers and booleans are written as text, as in <price>12.5</price>, with no XML Schema type information.
  • Namespaces get no special handling; provide keys like "soap:Envelope" and an "@xmlns:soap" attribute yourself and they are emitted as given.
  • No CDATA sections are produced; special characters are always escaped as entities.
  • An object or array used as an attribute value is written as a JSON string.

FAQ

How do I set the root element name?

Wrap your data in an object with exactly one key, e.g. {"order": {...}}. If there are several keys, or that single value is an array, <root> is used instead.

How do I produce several elements with the same name?

Give an array: {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag>. For a <tags> wrapper around them, use {"tags": {"tag": [...]}}.

Can JSON keys contain spaces or non-English letters?

Unicode letters such as Korean or accented characters are valid in XML names and kept as is. Spaces, /, and @ anywhere but the start are replaced with _, so confirm the tag names match what the receiver expects.