Gearboxly
Programming

How to Format and Validate JSON

By Gearboxly5 min read

JSON is everywhere — APIs, config files, data exports — and it's easy to read when it's neatly formatted and maddening when it's a single minified line or riddled with a stray comma. Formatting makes it readable; validating catches the tiny syntax slips that stop it parsing.

This guide covers how to format (pretty-print) JSON, how to validate it, and the handful of syntax rules behind almost every JSON error.

What you need

  • The JSON string you want to tidy or check.
  • A JSON formatter/validator (a browser-based one keeps your data private).
  • A basic grasp of the rules below — they explain most errors.

Step-by-step

  1. 1

    Paste your JSON into a formatter

    Drop the raw or minified JSON into a formatter. It re-indents the structure with consistent spacing so nested objects and arrays become readable — the fastest way to understand an unfamiliar payload.

  2. 2

    Read the validation result

    A good formatter validates as it formats, pointing to the line and character of the first error. JSON is strict, so it either parses perfectly or fails at a specific spot — the error location is your clue.

  3. 3

    Fix the common syntax errors

    Most failures are: a trailing comma after the last item, single quotes instead of double quotes (JSON requires double), missing quotes around keys, or unmatched brackets/braces. Fix the flagged spot and re-validate.

  4. 4

    Check data types

    Confirm strings are quoted, numbers aren't, booleans are true/false lowercase, and there are no comments (standard JSON doesn't allow them). These type slips cause silent bugs even when it parses.

  5. 5

    Minify or copy the clean result

    Once it's valid, copy the formatted version for readability, or minify it (strip whitespace) for transport where size matters. Keep a formatted copy for humans and a minified one for machines.

Examples

  • A one-line API response of 4,000 characters becomes a clear, indented tree — instantly revealing the nested structure you needed.
  • A parse error at 'line 12, column 3' turns out to be a trailing comma after the last array item — the classic JSON mistake.

Tips

  • JSON requires double quotes — single quotes are the number-one beginner error.
  • No trailing commas: the last item in an object or array must not be followed by a comma.
  • Standard JSON has no comments; strip them or use JSON5/JSONC only where supported.
  • Use a browser-based tool so sensitive payloads aren't uploaded anywhere.
  • Keep both a pretty version (for reading) and a minified version (for sending).

Common mistakes

  • Single quotes. JSON only allows double quotes around strings and keys.
  • Trailing comma. Remove the comma after the last element in an object or array.
  • Unquoted keys. Every key must be a double-quoted string.
  • Adding comments. Standard JSON doesn't support comments; remove them or use a format that does.

Conclusion

Formatting turns unreadable JSON into a clear structure, and validating catches the small syntax slips — trailing commas, single quotes, unquoted keys — behind almost every error. Use a browser-based tool for privacy, keep both pretty and minified copies, and JSON stops being a headache.

Tools for this task

Frequently asked questions

Paste it into a JSON formatter, which re-indents the structure into readable, nested lines. A good one also validates it and flags any syntax errors as it goes.

Almost always a small syntax issue: a trailing comma, single instead of double quotes, an unquoted key, unmatched brackets, or an included comment. Validators point to the exact spot.

Standard JSON does not. If you need comments, use a superset like JSON5 or JSONC, but only where the consuming tool supports it — plain JSON parsers will reject them.

Only if the tool processes it in your browser without uploading. A browser-based formatter keeps sensitive data on your device.

Related guides