Whitespace is decoration; the parser ignores it
JSON ignores whitespace between tokens. {"a":1} and
{
"a": 1
}
parse to the same value. Whitespace is for humans — pick a form for the audience.
Two forms of JSON
- Compact — no whitespace, minimal bytes. Used on the wire (HTTP responses, logs, message queues). Nginx logs, gzip pipelines, network bandwidth all benefit.
- Pretty-printed — 2-space indent, one key per line. Used in source files (config), documentation, and debugging. Diffs cleanly in git.
Tools you should know
Every language has a pretty-print tool. Bash people: jq (powerful, query language built in). Python: python -m json.tool (stdlib, zero install). JS / Node: JSON.stringify(obj, null, 2). Rust: serde_json::to_string_pretty. They all do the same thing — round-trip the data, re-emit with formatting.
Principle: commit pretty-printed JSON to git. Send compact JSON over the wire. Never the other way around. Pretty-print on disk gives you readable diffs; compact on the wire gives you bandwidth and speed. The cost of one is the cost of running a formatter; the cost of mixing them up is unreadable diffs and bloated payloads.