What is the JSON indentation level convention? [closed]

Is there any such thing as the "standard" convention for JSON indentation level? Should it be 2 spaces, 3 spaces, 4 spaces, tabs delimited, or something else?

I tried to come across the official JSON site, but it is not stated there.


Solution 1:

JSON is a serialization format, not a presentation format.

As such, there is no "standard" indentation - JSON is typically sent as compactly as possible.

(That said, there is an option to JSON.stringify() to request "pretty printed" JSON - look at the space parameter at the MDN documentation)

Solution 2:

There is no standard. The JSON specification permits any number of whitespaces.

However, when you are pretty-printing JSON to make it readable (e.g. in config files) it is good practise to be consistent with the coding conventions of your project and use the same indendation level as you would for an JS object literal - which is often 4 (Crockford) or 2 spaces (Node.js).