<>
Runs in your browserNothing is uploadedData, CSV & JSON

JSON to XML

Convert JSON to indented XML. Keys under "@attr" become attributes and "#text" becomes element text.

Loading tool…
Short answer

JSON to XML converts JSON into indented, well-formed XML. Object keys become elements, arrays become repeated elements, keys under "@attr" become attributes and "#text" becomes the element text. Special characters are escaped and invalid names are made safe.

How does JSON map to XML?

Elements and arrays

Each key becomes an element holding its value. An array such as "author": ["A", "B"] becomes two author elements side by side, which is how XML usually lists things.

Attributes and text

An "@attr" object, such as {"@attr": {"id": "7"}}, becomes id="7" on the element. A "#text" value becomes the text inside an element that also has attributes or children.

Why use JSON to XML?

  • Talk to older systems. Many banking, publishing and government services still accept only XML.
  • Round trips. It uses the same "@attr" and "#text" convention as XML to JSON, so data can go back and forth.
  • Private. Conversion happens in this tab.

How to use JSON to XML, step by step

JSON to XML in PrintxPDF with a file loaded, options on the right and the run button below
JSON to XML with a file loaded: the steps below follow this screen.
  1. Paste JSON into JSON to XML. The example shows attributes, repeated elements and text together.
  2. Set the root name if needed. XML needs one root element. A JSON object with a single key uses that key; otherwise the root name you set wraps everything.
  3. Copy or download the XML. Save it as data.xml.

Frequently asked questions

What happens to keys that are not valid XML names?

Characters XML does not allow become underscores, and a name starting with a digit gets an underscore in front, so the output is always well-formed.

How are null and empty values written?

As an empty element such as <middleName/>.

Are special characters escaped?

Yes. &, <, > and quotes are written as entities, so text such as "A & B" is safe.

Looking for the long version? The guides cover each of these jobs in depth.