JSON Formatter, Validator & Minifier
Last reviewed on April 27, 2026.
Paste JSON into the input. The tool parses it, reports any error with line and column, and writes the formatted version to the output box. Switch indent, sort keys, or minify in the controls. Everything runs locally in your browser — no JSON ever leaves your device.
What "valid JSON" actually means
JSON is a subset of JavaScript object syntax with a strict set of rules. The parser will reject any of the things developers casually add when hand-writing config:
- Trailing commas.
{"a": 1,}is JSON5, not JSON. Strip the trailing comma. - Unquoted keys.
{a: 1}is JavaScript, not JSON. Quote every key. - Single-quoted strings.
{"a": 'hello'}is invalid. Strings must use double quotes. - Comments. JSON has no
//or/* */comments. If you need them, use a different format (YAML, JSONC, TOML). - Numbers with leading zeros.
{"a": 007}is invalid. Drop the leading zeros. - Special values.
NaN,Infinity, andundefinedare not JSON. They show up in JavaScript output but never round-trip cleanly.
The three jobs this tool does
Format
Reads the input, parses it as JSON, and re-emits it with consistent indentation. Two-space indent is the default — it is what most code editors and style guides settle on, fits comfortably on a 16:9 screen, and survives diffing reasonably well. Switch to four if you are working in a codebase that already uses four; consistency beats preference.
Minify
Strips every byte of whitespace not strictly inside a string. The output is the smallest valid representation of the same data. Useful when copying a config into a single environment variable, embedding JSON in a JWT payload (see the Base64 encoder), or shipping a fixture inline in a test file. The minifier also normalizes string escapes, so "A" becomes "A" if the original had been over-escaped.
Sort keys
Recursively sorts every object's keys alphabetically. Useful for stable diffs across runs (so two programs that emit the same data in different key orders produce identical output), and for human readability when the input has dozens of fields. Sorting does not change array order — JSON arrays are ordered by definition; sorting them silently would change meaning.
Worked example: comparing two JSON files
You have two configuration files that should be the same but produce different behavior. The fastest path to the difference:
- Format both files with the same indent and the sort-keys option on.
- Diff the formatted output line by line.
- Real differences now show up as line-level changes, not as cosmetic re-orderings.
The same trick works for API responses captured in different runs, snapshot test fixtures, and config exported from different environments.
Reading parse errors
The browser's JSON parser reports errors with a position. The tool above translates that position into a line-and-column reference. The most common errors and what they actually mean:
| Error | What it means | Fix |
|---|---|---|
Unexpected token } | A trailing comma before the closing brace | Remove the comma |
| Unexpected end of JSON input | Truncated input — opening brace without a closing one | Check that the paste copied the whole thing |
Unexpected token ' | Single-quoted string | Replace single quotes with double quotes |
| Unexpected number | Usually a leading-zero number or a misplaced minus sign | Strip the leading zero or fix the sign |
Unexpected token i (or N) | Infinity or NaN in the input | Replace with null or remove the field |
Common mistakes
- Pasting JSON wrapped in JavaScript.
const data = { ... };is not JSON. Strip the variable assignment. - Pasting from a logger. Many loggers prefix lines with timestamps and severities, breaking the JSON. Trim the prefix before pasting.
- Mixing CRLF and LF line endings. The parser does not care, but the diff tool you compare against later might. Pick one and normalize.
- Assuming property order matters. JSON objects are unordered by spec. If your code relies on the order of keys, fix the code, not the JSON.
- Treating big integers as numbers. JavaScript loses precision above 2^53 − 1. If your JSON contains 19-digit IDs (Twitter snowflakes, certain database keys), parse them as strings before they hit JavaScript.
Where this fits with the other tools on the site
Use the JSON formatter alongside the URL encoder when you are debugging an API request that puts JSON in a query parameter. After decoding a Base64-encoded payload with the Base64 encoder, paste the result here to validate it. For test data you do not want to invent by hand, generate fake values with the fake prop-data generator, and check the resulting JSON shape here.