JSON to XML Converter - Convert JSON and XML Online

Tools / Converters / JSON to XML

JSON ↔ XML Converter

Conversion rules

  • A key starting with @ becomes an attribute: {"@id": "7"} → <book id="7">.
  • "#text" is the text of an element that also has attributes: {"@lang": "en", "#text": "Hi"} → <note lang="en">Hi</note>.
  • An array repeats the element under the same name: "tag": ["a", "b"] → <tag>a</tag><tag>b</tag>. An array inside an array is wrapped in <item>. An empty array gives an empty element: "tag": [] → <tag/>.
  • Root: if the JSON is an object with a single key, that key becomes the root element; otherwise everything is wrapped in <root>, or in the name you type.
  • Names are made valid for XML: invalid characters become _, and a name starting with a digit, dot or hyphen gets a leading _ ("1" → <_1>, "first name" → <first_name>). & < > are escaped; null and "" give an empty element.
  • A prefix such as "a:b" is kept only when "@xmlns:a" is declared on that element or an ancestor; otherwise it becomes <a_b>. If two attribute names end up the same after cleaning, the second gets _2: "@a b" and "@a_b" → a_b and a_b_2.
  • XML → JSON: repeated sibling elements become an array, an element with only text becomes its value, attributes get @. Values stay strings unless you turn on number and true/false detection.

How JSON maps to XML

JSON and XML both describe trees, but with different building blocks: XML has attributes, mixed text and repeated elements, while JSON has arrays, numbers and booleans. There is no single official mapping between them, so this converter follows one fixed, documented convention. You can predict the output and convert it back.

How to use it

  1. 1 Paste JSON into the left box, or choose XML → JSON and paste XML. The result updates as you type.
  2. 2 Pick the indent. For JSON → XML you can also set the root element name and leave out the <?xml?> declaration.
  3. 3 Copy the result or download it as a .xml or .json file. Clicking the other direction moves the result into the input, so you can check the round trip.

Why a one-item array comes back as a single value

XML has no array type: a list is simply the same element written several times. {"tag": ["a", "b"]} becomes two <tag> elements and returns as an array, but {"tag": ["a"]} becomes one <tag> element, which looks exactly like a plain value and returns as "a". If your code expects an array, wrap single values in one after reading the JSON.

Why numbers come back as strings

In XML everything is text: <year>1813</year> carries no type. By default every value stays a string, because guessing damages real data: a postcode "007" would turn into 7, and an ID like 12345678901234567890 would lose digits. Turn on number and true/false detection only when you know the fields are numeric. Even then only values that print back identically are converted, so "1.50" and "007" stay strings. In the other direction, JSON → XML, numbers are copied exactly as written, so 12345678901234567890 and 1.10 keep every digit; if your browser is too old for that, a warning lists the numbers it changed.

Characters that are not allowed in XML names

A JSON key can be any text; an XML element name cannot. It must not start with a digit, hyphen or dot, and cannot contain spaces, slashes or most punctuation. "2nd floor" becomes <_2nd_floor> and "price/kg" becomes <price_kg>. Two keys that end up with the same name look like a repeated element when converted back, so rename such keys in the source if you need a clean round trip.

Escaping and error messages

The characters & < > in text are written as &amp; &lt; &gt;, and quotes in attributes as &quot;, so the output always parses. If the JSON is broken you see the parser’s own message, such as an unexpected token and its position. For XML the browser’s parser reports the first problem, usually a tag that is not closed, tags closed in the wrong order, or a bare & that should be &amp;.

JSON to XML: frequently asked questions

No. There is no official mapping, so tools differ on attributes, arrays and the root element. This page uses a widely used convention: keys starting with @ are attributes, #text is the element text, and arrays repeat the element. If the receiving system expects a different shape, adjust the JSON keys before converting.
New
Roman Numeral Converter Convert numbers from 1 to 3999 to Roman numerals and back. Strict checking explains why IIII or IC is wrong, with a step-by-step breakdown.
Popular Today
Cooking Converter Convert cups, tablespoons, teaspoons and fluid ounces to grams and ounces for 40 common ingredients — flour, sugar, butter, honey, rice and more — using each ingredient's real density. Runs in your browser.

Related Converters

Word to PDF Convert Word to PDF for free: upload a DOC, DOCX, ODT or RTF file and download a properly formatted PDF in seconds - no registration or watermark.
PDF to Word Convert PDF to Word for free: upload a PDF and download an editable DOCX in seconds - no registration, no watermark and nothing to install.
Image Converter Free image converter: pick PNG, JPG, WebP, GIF or BMP and convert any picture in your browser - your photos are never uploaded to a server.
WebP to PNG Convert WebP to PNG for free: transparency is preserved and the image never leaves your device - the whole conversion runs in your browser.
PNG to JPG Convert PNG to JPG for free: pick the quality and a background colour for transparent areas, all in your browser with no upload.

Other Tools You May Like

MD5 Hash Generator Free MD5 hash generator: turn any text or file into an MD5 checksum in your browser - useful for integrity checks and quick fingerprinting.
Base64 Encoder & Decoder Free Base64 encoder and decoder: convert text or files to Base64 and back, entirely in your browser - nothing is uploaded to a server.
Word Counter Free word counter: paste any text to count words, characters, sentences and paragraphs, and see the estimated reading time - nothing leaves your browser.
Character Counter Free character counter: count characters with and without spaces, plus words and lines, and check SEO limits for titles and meta descriptions.
Keyword Density Checker Free keyword density checker: paste text or a URL to see how often each word and phrase appears, with percentages for one, two and three-word terms.