All guides

Readable or compact JSON, which to choose

Published · Updated 3 min read

A JSON file is a way of writing data as text: a list of plots, an application's settings, one website's reply to another. The same content can be written in two ways, readable or compact, and the choice depends on what you want to do with it.

The readable form

In the readable form, each piece of information sits on its own line and is shifted by a few spaces according to its place, which is called indentation. You see at a glance what is inside what. It is the form to use when you reread a file, compare it with another version or look for a mistake. Two or four spaces of shift look the same to the eye. Four spaces make the file a little airier, but also heavier, because every space counts.

The compact form

In the compact form, called minified, everything is written one after the other, with no line break or unnecessary space. The content is exactly the same, but it becomes hard for a person to read. This form is used when the file travels: sent to a site, stored in large numbers, or loaded by a web page that must display quickly. On a list of about forty items, going from four spaces to two removes about a fifth of the weight, and minifying removes nearly two fifths compared with the two-space version. What disappears is only spaces and line breaks.

How to choose

Keep the readable form for anything you edit by hand or share with someone who needs to understand it. Switch to the compact form at the last moment, just before sending or publishing. Always keep the readable version: you can go back from the compact form to the readable one at any time, but only if you kept the file.

When to use each form

A developer rereading a server response, a site manager checking a settings file or a person preparing data for a spreadsheet are better off with the readable form. A site that sends its data to visitors, or an application that stores thousands of records, gains speed with the compact form.

Check the result

Minified JSON must read back exactly like the original. Open it with the formatter: if the file displays correctly, no data was lost. If it displays an error, the starting text was not valid JSON, and it needs fixing before you go on.

Format JSON

To reduce the weight of a file, see Minify JSON.

Frequently asked questions

Does minifying JSON change the data?
No. Only spaces and line breaks disappear. The content, the order and the values stay identical.
How much weight do you save by minifying?
On a list of about forty items, going from four spaces to two removes about a fifth of the weight, and minifying removes nearly two fifths compared with two spaces. The gain depends on the number of lines and the depth of the file.
Can you go back to the readable form after minifying?
Yes, by opening the file with the formatter. It restores the indentation, but not old comments or manual layout, which is why keeping the readable version is worthwhile.
What if the formatter shows an error?
The starting text is not valid JSON: an extra comma, a missing quotation mark or an apostrophe in place of a quotation mark are the most frequent causes.