Open tools · 0

About

JSON to XML

Paste JSON, or drop a .json file, and well-formed XML is written as you type, with an XML declaration on top and the indent you pick. When the JSON is an object with one key that does not hold an array, that key names the root element; anything else goes inside one called root, or whatever you type as the Root element.

What it does

  • Keys starting with @ become attributes and a #text key the element’s text: {"price": {"@currency": "EUR", "#text": "9.99"}} gives <price currency="EUR">9.99</price>.
  • An array repeats its key, so {"tag": ["a", "b"]} gives <tag>a</tag> and <tag>b</tag> side by side.
  • An array at the top becomes <item> elements inside the root, since an XML document has exactly one root element.
  • An array inside an array becomes one element with an <item> for each value, so the two lists stay apart.
  • Namespace prefixes such as dc:creator are kept wherever an @xmlns:dc key above them declares them.
  • A key XML cannot use as a name is rewritten and listed: first name becomes <first-name>, and 2nd becomes <_2nd>.
  • Numbers keep their text, so 1.50 stays 1.50; <, & and quotes are escaped, and accents stay as they are.
  • A null becomes an empty element, such as <none/>, and the notes say so.

How to use it

  1. Paste the JSON, or drop the .json file on the window.
  2. Pick an indent or One line, and type a Root element name if the data needs one.
  3. Read the notes on anything renamed, wrapped or left out.
  4. Copy the XML, or download it as a .xml file.

What it does not do

  • Types in the XML: 36, true and 1.50 all become text, the only kind of value XML has, and come back as strings.
  • Empty arrays: an empty list has no element to write, so it is left out and the notes say so.
  • A schema or a DTD: the XML is written by the rule above, not checked against one it should fit.

Questions

How do I make an attribute instead of an element?

Start the key with @: {"book": {"@id": "7", "title": "Dune"}} gives <book id="7"><title>Dune</title></book>. A value under #text becomes the element’s own text, beside its attributes.

Why is my array inside a <root> element?

An XML document has one root element, and an array would make one for each item. So the items go inside <root>, as <item> elements when the array is at the top. Type another name as the Root element to change root.

Will converting the XML back give me my JSON?

The shape, yes, but numbers and true come back as strings, a one-item array as a single value, and a null as an empty string. That is XML’s limit: it holds text and nothing else.

Does the result start with an XML declaration?

Yes: every result starts with <?xml version="1.0" encoding="UTF-8"?>, and the file downloads in UTF-8 to match, so accents and emoji need no escaping.

Everything here runs in your browser. Nothing you type, paste or open is uploaded, and there is no account and no queue. How that works.

Often used with

More in Converters

  • Unit Converter: Convert length, weight, temperature, volume, area, speed, data size and nine more quantities, both ways, with the formula.
  • Base64 Encode & Decode: Encode text or files to Base64 and decode it back: URL-safe, MIME line breaks, data URIs, and images you can preview.
  • CSV Viewer & Editor: Open a CSV, Excel or JSON file as a table, tidy it (spaces, duplicates, garbled letters, dates and numbers) and save it as CSV, .xlsx or JSON.

All toolsAbout utilbrewPrivacy