JSON Formatter
Pretty-print, minify, and validate JSON — paste it in and see errors instantly.
Format mode re-indents JSON into a readable tree with 2-space, 4-space, or tab indentation. Minify mode strips every space and line break to one compact line for smaller payloads. Both first validate the JSON: if it parses, you get a green “Valid JSON”; if not, the parser’s exact error shows where it broke.
What formatting and validation do
JSON (JavaScript Object Notation) is a text format for structured data, but real-world JSON often arrives on a single crammed line or with inconsistent spacing. Formatting parses the data and re-prints it with consistent indentation so nesting is obvious at a glance. Minifying does the opposite — it removes all optional whitespace to shrink the file for storage or network transfer. Validation is the shared first step: the tool runs the text through a strict parser, so anything it accepts is guaranteed to be well-formed JSON.
Why the same parser does both
Whether you format or minify, the tool calls the same strict JSON parser and rebuilds the output from the parsed structure rather than editing your text directly. That is why a stray comma or a single quote stops the process with an error instead of producing broken output — the parser refuses to guess. Only valid input reaches the formatting or minifying step, so the result is always canonical, machine-readable JSON.
- 1 Paste your JSON. Drop the raw text into the input box — a single line or many lines both work.
- 2 Choose Format or Minify. Format re-indents for reading; Minify collapses everything to one line.
- 3 Pick an indent (Format only). Select 2 spaces, 4 spaces, or a tab to match your project’s style.
- 4 Read the status. A green “Valid JSON” means it parsed; a red error shows the parser’s message and roughly where it failed.
- 5 Fix errors and copy. Correct any reported issue — often a trailing comma or single quotes — then copy the clean output.
Core JSON syntax rules
Break any of these and the parser rejects the whole document.
| Rule | Allowed | Not allowed |
|---|---|---|
| String quotes | Double quotes only: "name" | Single quotes: ’name’ |
| Object keys | Every key is a double-quoted string | Unquoted keys like name: |
| Trailing commas | No comma after the last item | [1, 2, 3,] or {"a": 1,} |
| Comments | None — JSON has no comment syntax | // line or /* block */ comments |
| Values | string, number, true, false, null, object, array | undefined, NaN, Infinity, functions |
| Numbers | 42, -3.14, 1.2e10 | Leading zeros (01) or hex (0xFF) |
Reading the error message
When JSON is invalid the tool shows the browser’s native parser message, such as “Unexpected token } in JSON” or “Unexpected end of JSON input.” These messages point to the first place the parser could not continue, which is usually at or just before the real mistake. The most common culprits are a trailing comma before a closing bracket, single quotes instead of double quotes, an unquoted key, or a missing bracket. Fix the earliest error and re-check, since one broken bracket can cascade into several confusing messages.