JSON Formatter & Validator
Format, minify and validate JSON with syntax highlighting. Shows error locations, key count, nesting depth and size stats
Format, Minify, and Validate in One Pass
Paste raw JSON into the input box and the tool parses it with the browser's native JSON.parse, then immediately renders three things: the prettified version with your chosen indentation (2 spaces by default), the minified single-line version, and a stats panel showing total key count, maximum nesting depth, and minified byte size. If the JSON is malformed, the parser surfaces the exact character position of the failure so you can jump straight to the offending comma or unquoted key.
JSON is defined by RFC 8259, which is stricter than most people remember. Trailing commas are not allowed. Single-quoted strings are not allowed. Comments are not allowed. Unquoted property names are not allowed. If you're hand-editing config and the parser screams, those four rules are nearly always the cause. JSON5 and JSONC (used in tsconfig.json and VS Code settings) relax these rules, but they're separate dialects and standard parsers reject them.
Indent Width Conventions Across Ecosystems
There's no single right indent width, but conventions per ecosystem are remarkably stable. NPM's package.json and most JavaScript tooling default to 2 spaces. Python's standard library `json.dump(indent=4)` and most Java tools default to 4. Go's `encoding/json` MarshalIndent leaves the choice to the caller but examples almost always use a single tab. The tool defaults to 2 spaces because that's the dominant choice for files that get committed to JavaScript repos, but you can switch to 4 spaces or tabs from the dropdown.
Pick your indent based on the file's neighbours: if everything else in the project is 2 spaces, match it; consistency across files matters more than the absolute value. For deeply nested structures (depth 5+), 2 spaces stops the lines running off the screen. For shallow configs where readability matters more than line length, 4 spaces helps the eye trace nested keys.
Common JSON Errors and Fixes
| Error | Cause | Fix |
|---|---|---|
| Unexpected token } in JSON | Trailing comma before closing brace | Remove the comma |
| Unexpected token ' in JSON | Single quotes used for strings | Change to double quotes |
| Unexpected token in JSON at position 0 | BOM or whitespace before { | Strip leading bytes |
| Unexpected end of JSON input | Truncated payload, missing brace | Check the full response |
| Bad escape character | Backslash not followed by valid escape | Double the backslash |
Frequently Asked Questions
Why does my JSON fail validation when it looks fine?
The most common silent killers are: trailing commas (allowed in JavaScript, not in JSON), single quotes around strings or keys, unquoted property names, and JavaScript-style // or /* */ comments. JSON also requires keys to be strings, even when they look like numbers; `{1: 'a'}` is invalid, you need `{"1": "a"}`.
What does maximum depth mean in the stats panel?
Depth counts how many nested levels exist between the root and the deepest leaf. A flat object like `{a: 1}` has depth 1. `{a: {b: 1}}` has depth 2. APIs that return paginated, deeply nested resource graphs often hit depth 6+, which is a flag that the response shape is making consumers do too much traversal. Consider flattening or denormalising on the server.
Can I format JSON with comments (JSONC)?
Not with this tool's default mode, because JSONC is not valid JSON per RFC 8259 and the browser's JSON.parse rejects it. VS Code uses JSONC for settings.json and tsconfig.json by stripping comments before parsing. If your file contains // or /* */ comments, remove them first or open it in a JSONC-aware editor.
Is the data sent anywhere?
No. The whole pipeline runs in your browser using JSON.parse and JSON.stringify. Nothing is uploaded, logged, or cached on a server. You can paste API responses containing tokens or PII without worrying about leakage.
Related Tools
JSON Validator
Validate JSON syntax and find errors with line numbers online for free. Real-time validation as you type with detailed error messages and stats.
JSON Prettifier
Format and pretty-print JSON with proper indentation online. Choose 2 spaces, 4 spaces, or tabs. Instant formatting with error detection and stats.
JSON Minifier
Minify JSON by removing all whitespace and formatting. See the size reduction instantly. Free online JSON compressor with copy button.