DEVELOPER TOOL

JSON to XML Converter (and XML to JSON)

Paste JSON to get well-formed XML, or press Swap direction to turn XML into JSON. Every mapping rule is listed under the tool, so you know exactly what happens to attributes, arrays, text and awkward key names.

JSON → XML

    
Mapping rules in use

    About this tool

    JSON and XML do not describe data the same way. XML has attributes, text content, repeated elements, comments and namespaces. JSON has objects, arrays, strings, numbers, booleans and null. Because there is no official standard for converting between them, every converter has to choose a set of rules, and most tools do not say which rules they chose. This converter uses one documented convention in both directions and lists the rules under the tool, so you can predict the output before you paste anything. Everything runs in your browser; nothing is uploaded.

    How to use the converter

    1. Paste JSON into the input box. A small product catalog is loaded as a sample.
    2. Set the options: the root element name, the element name used for items of a top-level array, the attribute prefix (@ by default), the indent and whether strings go into CDATA sections.
    3. Click Convert. The status line counts elements and attributes, and any renamed keys or dropped values are listed underneath.
    4. Click Swap direction to convert XML to JSON instead. If there is output, it moves into the input box, so you can check a round trip in two clicks.
    5. Copy or download the result as converted.xml or converted.json.

    JSON to XML mapping rules

    Escaping and CDATA

    The W3C XML 1.0 specification says a literal & or < must never appear in text, and that > must be escaped in the sequence ]]>. This tool escapes all three in text, and in attribute values (which it writes in double quotes) it escapes both quote characters too:

    CharacterIn textIn attribute values
    &&amp;&amp;
    <&lt;&lt;
    >&gt;&gt;
    "left as is&quot;
    'left as is&apos;

    Choose a CDATA option to write strings as <![CDATA[...]]> instead, either for every string or only for strings that contain &, < or >. A CDATA section cannot contain ]]>, so the tool splits the section at that point. Numbers, booleans and attribute values are never put in CDATA.

    XML to JSON mapping rules

    Watch out for leading zeros. ZIP codes, SKUs and phone numbers such as 00731 look numeric, but turning them into numbers would lose the zeros. Even with conversion on, this tool only converts text that is a valid JSON number (as defined in RFC 8259, which rules out leading zeros), so 00731 stays a string. Conversion can still change formatting: 12.50 becomes 12.5. Integers larger than 9,007,199,254,740,991 (the largest integer a JavaScript number holds exactly) are left as strings.

    Worked example

    The sample JSON has a single top-level key, catalog, so it becomes the root. The product array becomes two product elements, @id becomes an attribute, the & and < in the strings are escaped, null becomes a self-closing element, and the key 2for1 is renamed _2for1 because an XML name cannot start with a digit. Convert gives:

    <?xml version="1.0" encoding="UTF-8"?>
    <catalog updated="2026-10-01">
      <product id="p100">
        <name>Trail Running Shoes</name>
        <price currency="USD">89.99</price>
        <tags>
          <tag>outdoor</tag>
          <tag>footwear</tag>
        </tags>
        <inStock>true</inStock>
      </product>
      <product id="p101">
        <name>Tom &amp; Jerry Socks</name>
        <price currency="USD">12.5</price>
        <sku>00731</sku>
        <note>Ships in &lt;2 days</note>
        <_2for1>false</_2for1>
        <discontinued/>
      </product>
    </catalog>

    Swap the direction and convert back, and the first product comes out as:

    {
      "catalog": {
        "@updated": "2026-10-01",
        "product": [
          {
            "@id": "p100",
            "name": "Trail Running Shoes",
            "price": {
              "@currency": "USD",
              "#text": "89.99"
            },
            "tags": {
              "tag": [
                "outdoor",
                "footwear"
              ]
            },
            "inStock": "true"
          },

    The structure survives, but the types do not: 89.99 and true are now strings, because XML text has no type. Tick Convert numbers and true/false to get them back as a number and a boolean, while 00731 stays a string. The key _2for1 keeps its new name.

    Common mistakes

    Use cases

    Related tools: tidy the input first with the JSON Formatter or the XML Formatter, convert config files with the YAML to JSON Converter, or flatten records into a spreadsheet with JSON to CSV.

    Related reading

    For a longer explanation, read our guide: JSON vs XML: differences and when to use each.

    Frequently asked questions

    Is there a standard way to convert JSON to XML?

    No single standard exists, so each library picks its own convention for attributes and text. This tool uses an @ prefix for attributes and a #text key for text, the same defaults as the Python xmltodict library, and lets you change the attribute prefix to match whatever convention your other code expects.

    Why do my numbers come back as strings after converting XML to JSON?

    XML stores everything as text, so the converter cannot know whether 42 was meant as a number or as a code. Strings are the safe default. Tick the option to convert numbers and true or false, and values with leading zeros such as ZIP codes will still stay strings.

    How do I convert a JSON array to XML?

    Paste the array as it is. A top-level array is wrapped in the root element and each entry becomes an element named by the array item name option, item by default. An array stored under a key, such as "product": [...], becomes repeated product elements instead.

    Is my data uploaded anywhere?

    No. Both directions run in JavaScript in your browser tab, using the built-in JSON parser and XML parser. Nothing is sent to a server, so you can convert internal API responses or configuration files, and the tool keeps working offline once the page has loaded.

    Can I convert XML with namespaces to JSON?

    Yes. Element and attribute names keep their prefixes, so inv:stock becomes the key "inv:stock", and namespace declarations such as xmlns:inv become ordinary attribute keys. Converting that JSON back to XML writes the same prefixes and declarations, so the namespaces survive a round trip.

    What happens to XML comments when converting to JSON?

    They are dropped, along with processing instructions such as xml-stylesheet, because JSON has no place for them. A note under the status line tells you how many were skipped. If you need to keep comments, store them in an element or attribute before converting.