JSON to XML converter

Convert JSON to XML that is well-formed. Keys starting with "@_" become attributes and "#text" becomes element text, so XML converted with this site round-trips cleanly.

JSON

XML

Waiting for input

What you get

How each result is checked

  1. The output is checked for well-formedness with an XML validator.
  2. The XML is parsed back and compared with your data. Because XML has no data types, values are compared as text.

What can't convert exactly

  • XML has no numbers, booleans or null: they are written as text, and null becomes an empty element.
  • Keys that are not valid XML names (spaces, leading digits) are renamed, and you are told which.
  • A one-item array looks the same as a single value in XML, and empty arrays have no XML form.

Questions

How do I make an attribute?

Prefix the key with "@_", for example { "book": { "@_id": "bk101", "title": "…" } } gives <book id="bk101">.

What if my JSON has several top-level keys?

XML needs a single root element, so the data is wrapped in <root> (you can rename it in the options).

How do I convert JSON to XML with a root element?

XML needs one root element. If your JSON has one top-level key, it becomes the root; otherwise the data is wrapped in <root>, and you can rename it and the array item element in the options.

How do I convert JSON to XML online?

Paste your JSON or open a file on the left (or click Example). The XML appears on the right as you type, already checked. Copy it, or download it as a file. Nothing is uploaded.

Can the XML output be wrong?

Every result is checked before it is shown (the checks are listed on this page). If a check fails, the page says "Review needed" and why, instead of presenting the output as correct, and anything that cannot convert exactly is named in the notes.