JSON Formatter
Format, beautify, and validate JSON with customizable indentation. Paste raw JSON, pick 2-space, 4-space, or tab indent, and get a clean readable result instantly.
TL;DR. Paste any JSON string into the input box, choose your indentation style, and click Format. The tool runs JSON.parse() to validate the input and JSON.stringify(value, null, indent) to re-serialise it with consistent whitespace. If the JSON is invalid, the exact error message and character position appear so you can fix the syntax. Click Minify to strip all whitespace for APIs or hashing. Everything runs in your browser - no data leaves your machine.
How to use the JSON formatter
- Paste your JSON. Copy a response from an API, a
.jsonconfig file, or a minified blob from a network request and paste it into the input box. The tool accepts any valid JSON value: an object{ }, array[ ], string, number, boolean, ornull. - Choose indentation. Select 2 Spaces for compact diffs and APIs, 4 Spaces for Python or Java codebases, or Tabs if your editor convention requires it. All three produce spec-valid JSON.
- Click Format or Minify. Format adds indentation and newlines for readability. Minify removes all whitespace to produce the smallest possible string, useful for signature inputs, storage, or network payloads.
- Read the error if validation fails.
JSON.parse()throws aSyntaxErrorwith the exact position of the problem. Common fixes: remove trailing commas, replace single quotes with double quotes, quote unquoted keys, or delete a BOM character at the start. - Copy the output. Click the Copy button to put the formatted or minified result on your clipboard. The line count and byte size are shown so you can track payload changes when switching indentation styles.
JSON syntax cheatsheet
The JSON spec (RFC 8259) is small but unforgiving. Every token below is exact - no deviation is allowed.
| Token / Rule | Detail |
|---|---|
| null | The null value. Not the string "null", not 0, not false. |
| true / false | Boolean literals. Must be lowercase. |
| "string" | Strings must use double quotes. Single quotes are not valid JSON. |
| \" \\ | Escaped double quote / escaped backslash inside a string. |
| \n \t \r | Newline / tab / carriage return inside a string. |
| \uXXXX | Unicode escape: any code point as 4 hex digits, e.g. \u00e9 = e with accent. |
| 123 / 1.5e2 | Numbers: integers and floats. No NaN, no Infinity, no leading zeros. |
| [ ] | Array. Items separated by commas. Trailing comma not allowed. |
| { } | Object. Key-value pairs, keys must be quoted strings. |
| ISO 8601 | JSON has no date type. Use "2026-04-20T12:00:00Z" strings by convention. |
| No comments | JSON forbids // and /* */ comments. Use a JSONC parser for config files. |
| No trailing , | {"a":1,} and [1,2,] are syntax errors. Remove trailing commas. |
Common JSON errors and how to fix them
- Trailing comma:
{"a":1,}or[1,2,]— remove the comma after the last item. This is valid JavaScript but the JSON spec forbids it. - Single-quoted strings:
{'name':'Jim'}— replace every'with". JSON requires double quotes on both keys and values. - Unquoted keys:
{name:"Jim"}— quote the key:{"name":"Jim"}. - NaN or Infinity: These are valid JavaScript numbers but not valid JSON. Replace with
nullor a quoted string like"Infinity"before serialising. - BOM at start of file: Some Windows text editors prepend a UTF-8 byte-order mark (
U+FEFF).JSON.parse()will throw immediately. Strip it by deleting the first invisible character. - Comments inside JSON: If your file has
//or/* */comments, it is JSONC (used by tsconfig.json, VS Code settings). Strip comments before passing to this tool, or use a JSONC-aware parser likejsonc-parser.
Frequently asked questions
What does a JSON formatter actually do?+
What is the difference between JSON, JSON5, and JSONC?+
Why does my JSON throw "Unexpected token" errors?+
When should I use 2-space, 4-space, or tab indentation?+
What is canonical JSON and why does indentation matter for hashing?+
Is there a size limit? What happens at 500 MB?+
Related developer tools
- Regex Tester
Test JavaScript regular expressions live
- Hash Generator
MD5, SHA-1, SHA-256 in the browser
- Base64 Converter
Encode and decode Base64 strings
- Timestamp Converter
Convert Unix timestamps to readable dates