Home / Data tools / JSON to XML pretty print

JSON to XML Pretty Print

Convert JSON to XML and control exactly how it is laid out: indentation, empty tags, key order and the declaration.

Formatting options

  • Indentation: 2 spaces, 4 spaces or a tab for each level.
  • Minified: no line breaks or indentation, for the smallest output.
  • Self-closing empty tags: write <a/> instead of <a></a> for empty elements.
  • Sort keys: order elements alphabetically, which makes files easier to compare.
  • XML declaration: include or leave out the opening line.

Pretty or minified?

Indented XML is easier for people to read, review and compare in version control, so it suits configuration files and debugging. Minified XML is smaller, which helps when sending data between systems. The size line under the output shows how many bytes each layout takes.

Whitespace and text

This converter puts text on the same line as its element, so indenting never adds spaces inside your text values. That avoids a common problem where pretty printing changes the data.

Sorted keys for comparing

When you compare two XML files, a different element order shows up as a change. Sorting keys gives both files the same order, so only real differences remain.

For the core options such as the root name and arrays, use the JSON to XML converter. To convert a file, see JSON to XML online. The JSON vs XML guide explains when to choose each format.

Frequently asked questions

How do I get indented XML?

Choose 2 spaces, 4 spaces or Tab. The output is formatted as you change the option.

How do I minify the XML?

Choose Minified. All line breaks and indentation are removed.

Does pretty printing change my text values?

No. Text stays on the same line as its element, so no extra whitespace is added inside values.

Why sort the keys?

A fixed order makes two XML files easy to compare, because only real differences remain.