JSON Formatting Best Practices

By the ToolPocket team · Updated 2026-12-05 · Editorial standards

JSON has no comments and few conventions, which is exactly why formatting discipline matters when humans have to read it.

APIs return JSON minified because machines do not care about whitespace. But configuration files, fixtures and debugging dumps are read by people, and badly formatted JSON slows every review down.

Two spaces is the common default

Two-space indentation is the de facto standard in the JavaScript ecosystem. Four spaces is fine if your project already uses it, but pick one and stay consistent within a file. Tabs are risky because different editors render them at different widths.

Keep keys stable and meaningful

Use lowerCamelCase or snake_case consistently — not both in the same payload. Avoid abbreviations that only the original author understands. A key such as user_id is clearer than uid when the data is shared.

Do not minify what humans read

Minification is for transport. Committed configuration and fixtures should be pretty-printed, so diffs are reviewable line by line. A minified config produces a one-line diff that nobody can check.

Order keys intentionally

Most parsers preserve insertion order, but do not rely on it for logic. For readability, group related keys together: identifiers first, then content, then timestamps.

Watch the trailing comma trap

JSON does not allow trailing commas. JavaScript object literals do. Copying a JS object into a JSON file is a common source of silent breakage; validate after every edit.

Format and validate together

Pretty-printing is not validation. A formatter that accepts invalid input teaches bad habits. The JSON formatter parses before it prints and reports the error position, so you catch problems while the context is fresh.

If the JSON came from a spreadsheet, the CSV to JSON converter builds the structure, and the formatter checks it.

← All guides