JSON Formatter
Paste any JSON to format, minify, or validate in real time. Errors are pinpointed by line; depth and key counts shown for inspection. Everything runs in your browser — nothing is sent to a server.
Bytes
0
Depth
0
Keys
0
How the JSON formatter works
The tool calls the browser's native JSON.parse() to validate input, then re-serializes with JSON.stringify(value, null, indent). The whole pipeline runs in your browser — your data never reaches a server.
Indent options:
- 2 spaces — the GitHub / npm / Prettier default. Compact and readable.
- 4 spaces — common in older Java and Python codebases.
- Tabs — preferred when teams allow per-developer indent width.
- Minify — strips all whitespace; smallest possible payload for HTTP responses or embedded config.
Stats: Bytes is the UTF-8 byte length of the output. Depth is the maximum nesting level (1 = a flat object/array, 2 = one level deep, etc.). Keys is the total count of object keys reachable from the root, including nested objects.
Error reporting: on invalid JSON the status banner turns red and shows the parser's message. The line number is parsed from the error string when available — V8 (Chrome, Node, Edge) and SpiderMonkey (Firefox) format the message slightly differently, so the line number is best-effort. The character position is always shown.
JSON cheat sheet
- Strings must use double quotes. Single quotes are not legal JSON.
- Object keys must also be double-quoted strings — bare identifiers (like in JavaScript) are not allowed.
- No trailing commas in objects or arrays — that's a JavaScript/JSON5 extension, not standard JSON.
- No comments. If you need them, use JSON5 or JSONC instead.
- Numbers can't have leading zeros (
007is invalid), and you can't useNaN,Infinity, orundefined. - Allowed values:
string,number,true,false,null,object,array. Nothing else. - Strings must escape
\\,\", and control characters. Forward slashes/may be escaped but don't have to be. - The whole document must be valid UTF-8. BOM is technically not allowed but many parsers tolerate it.
Use this tool to: lint API responses before storing them as fixtures, shrink JSON before embedding it in HTML, or quickly sanity-check a configuration file.
Frequently asked questions
How do I format JSON?
Paste raw JSON into the input on the left. The formatted output appears on the right in real time. Choose 2-space, 4-space, tab indent, or "Minify" to compress to one line.
What does the validator catch?
Trailing commas, missing quotes around keys, unescaped quotes inside strings, unbalanced brackets. The error banner shows the line and column where parsing fails (when the browser provides them).
Is my JSON sent to a server?
No. Everything runs in your browser via JavaScript's built-in JSON.parse and JSON.stringify. Nothing leaves your computer. No analytics on input content.
Why does my big JSON cause stats to lag?
JSON.parse + JSON.stringify is O(n). On 10MB+ inputs the browser may take a moment. The depth and key-count stats use a recursive walker, also O(n). For multi-megabyte JSON, type into a text file and use a CLI tool like `jq` instead.