JSON formatter, validator and minifier, free, in your browser
A JSON formatter takes compact or messy JSON and re-indents it so nested objects and arrays are easy to read; a validator checks it against the JSON specification and reports the line and character of the first error; a minifier removes whitespace to make it as small as possible. This tool does all three locally in your browser, supports 2-space, 4-space and tab indentation, can sort keys alphabetically, and never uploads your data.
Your files never leave your device. Processing happens in your browser. How that works.
How it works
- Paste JSON into the input box.
- Click Format to beautify, Minify to compact, or watch the validator flag any syntax error with its line number.
- Copy the result, download it as a .json file, or share the URL.
Runs as JavaScript inside this tab. Turn off your connection after the page loads and it still works.
JSON syntax reference
JSON (JavaScript Object Notation, RFC 8259 / ECMA-404) has six value types and no room for interpretation. Almost every validation error comes from one of the rules below.
Values
| Type | Example | Notes |
|---|---|---|
| Object | {"key": value} |
Keys must be strings in double quotes. Duplicate keys are allowed by the spec but most parsers keep the last one. |
| Array | [1, "two", null] |
Any mix of values. |
| String | "text" |
Double quotes only. Escape " \ and control characters: \" \\ \n \t \uXXXX. |
| Number | -12.5e3 |
No leading zeros (012), no +, no NaN, no Infinity, no hex. |
| Boolean | true / false |
Lowercase. |
| Null | null |
Lowercase. undefined is not JSON. |
Common errors and fixes
| Error | Cause | Fix |
|---|---|---|
Unexpected token } or ] |
Trailing comma after the last item | Remove the comma |
Unexpected token ' |
Single-quoted strings | Use double quotes |
| Expected double-quoted property name | Unquoted key ({a: 1}) |
Quote the key: {"a": 1} |
Unexpected token / |
Comments | Remove // and /* */ comments |
| Unexpected end of JSON input | Missing closing bracket or brace | Balance {} and [] |
| Bad control character in string | Literal newline inside a string | Use \n |
Unexpected token N / u |
NaN, Infinity or undefined |
Use null or a number |
| Unexpected number | Leading zero (007) or .5 |
Write 7 or 0.5 |
Related formats
- JSON5 and JSONC allow comments, trailing commas and single quotes. VS Code settings files are JSONC. Standard parsers reject them.
- NDJSON / JSON Lines: one JSON value per line, used for logs and streaming. Validate each line separately.
- JSON Schema describes the expected shape of a document; this tool checks syntax, not schema.
Whitespace and size
Formatting adds only whitespace. A 2-space indent typically grows a minified document by 20–40%; a 4-space indent by 40–80%. Minifying removes all insignificant whitespace and is what you should ship over the network (with gzip or brotli on top).
Sorting keys
Key order carries no meaning in JSON, but sorting makes two documents comparable in a diff tool. Sorting is recursive and stable; array order is never changed.
Worked examples
Format {"name":"TabbyTools","tools":45,"tags":["pdf","text"]} with 2-space indent:
{
"name": "TabbyTools",
"tools": 45,
"tags": [
"pdf",
"text"
]
}
56 characters become 84 (+50%).
Minify the block above back to one line: 56 characters, the smallest valid form.
Validate a trailing comma
{
"a": 1,
"b": [1, 2, 3],
}
Result: Invalid JSON: Expected double-quoted property name at line 4, column 1. The parser reached } where it expected another key after the comma. Remove the comma after ].
Sort keys for a clean diff: {"z":1,"a":{"y":2,"b":3}} becomes
{
"a": {
"b": 3,
"y": 2
},
"z": 1
}
JS object mode drops the quotes from keys that are valid identifiers, for pasting into JavaScript or TypeScript source: { name: "TabbyTools", tools: 45 }. This output is not valid JSON.
Frequently asked questions
Why does my JSON fail to validate?
The most common causes are trailing commas after the last item, single quotes instead of double quotes, unquoted keys, and comments. JSON allows none of these. The error message points to the exact position.
Is JSON with comments valid?
No. Standard JSON has no comment syntax. JSON5 and JSONC allow comments but most parsers reject them. Remove comments before validating.
Does formatting change my data?
No. Only whitespace changes. Number formatting, string escapes and key order are preserved unless you enable Sort keys.
How large a file can I format?
There is no fixed limit; the work runs on your device. Files of tens of megabytes format in a second or two in a modern browser.
Is my JSON uploaded anywhere?
No. Parsing and formatting happen entirely in your browser. The share link embeds the JSON in the URL only if you ask for it and it fits.
JSON formatter · last updated · changelog · part of Canned Tuna