{
"color": "red",
"count": 2
}Pretty-print is for a person reading a payload. Minify is for the bytes you send. JSON formatter parses the document and writes it back with the indent you pick: 0, 2, 4, or 8 spaces. Indent 2 puts each key on its own line and a blank before each value. Indent 0 writes the compact form, with no space after colons or commas.
The formatter checks that the text is JSON before it prints anything. A trailing comma or a missing comma stops it with the parser's line and column, and nothing is rewritten. Key order is preserved. Alphabetizing keys is a different page, and you want that when the next step is a diff. This page only changes whitespace.
{"color":"red","count":2}. Indentation set to 2. Set it to 0 for the compact line, or to 4 for a wider indent.
Indent 2: { "color": "red", "count": 2 } That is 34 bytes. Indent 0 is {"color":"red","count":2}, 25 bytes. Indent 4 is 38 bytes. Nine bytes separate the reading form from the compact form.
The indent control is the whole decision: two spaces to read, zero spaces when the byte count matters.
For {"color":"red","count":2}, indent 2 is 34 bytes and indent 0 is 25 bytes. The nine bytes are the newlines and the spaces around colons.
Key order stays as it was parsed. Sort JSON keys is the page that alphabetizes every level so two files diff cleanly.
Expected ',' or '}' after property value in JSON at position 16 (line 1 column 17), for {"color": "red" "count": 2}.
Yes. Both emit JSON.stringify of the value, with no extra whitespace. The minifier is the page aimed at that one result. This page is the indent control.
The value is parsed and printed as JSON. 2 stays 2. Strings keep their characters, with quotes and escapes written in JSON form.