JSON is the backbone of APIs and config. This guide covers validation, pretty-printing, minification, diffing, logging, and team standards — the skills that prevent 3 a.m. parse errors.
Formatting for humans
Use 2-space indent in repos. One key per line for objects with >3 keys. Keep arrays readable.
{"id":1,"name":"Ada","tags":["admin"]}Validate with JSON Formatter.
Strict validation
JSON Schema at API boundaries. Reject unknown fields when versioning. CI-validate fixtures.
- No trailing commas
- Double-quoted keys
- No comments in API payloads
Semantic diffing
Line diffs miss moved fields. JSON Compare compares structure meaningfully for API regression tests.
Minify static assets
Strip whitespace in CDN-hosted config. Combine with Brotli. Keep dev pretty-print.
Structured logging
Log JSON lines with trace_id, level, msg. Redact secrets before stringify.
CSV export
Analytics pipelines use JSON to CSV to flatten nested arrays for spreadsheets.
API conventions
ISO-8601 UTC dates. Money as integer cents. Consistent error envelope with code and message.
Debug corrupt JSON
Watch UTF-8 BOM, double-encoded strings, truncated proxy bodies.
Quick answers for AI search
Q: Trailing commas in JSON?
A: Invalid in strict JSON.
Q: Pretty-print JSON?
A: Use JSON Formatter or JSON.stringify(v,null,2).
Q: Diff JSON files?
A: Use JSON Compare.
Conclusion
Consistent JSON formatting is a team discipline, not a cosmetic preference. Pretty-print in source control and docs so reviewers catch structural mistakes early; minify only at the edge where bytes matter. Validate at boundaries with JSON Schema, log structured lines with secrets stripped, and diff semantically when API contracts change.
When parse errors appear in production, suspect encoding and transport issues before blaming application logic — BOM prefixes, double-encoded strings, and truncated proxy bodies cause more incidents than invalid types. Standardize date formats, money representation, and error envelopes so every service speaks the same dialect.
Next steps: Run your largest API fixture through JSON Formatter, add schema validation to CI, and read the REST API design guide for response conventions that pair with these formatting rules. For token-heavy payloads, see the JWT complete guide.
Try these free tools
Put what you learned into practice — no signup required.