How to fix invalid JSON — common errors and automatic repair
JSON is strict. A single misplaced comma or unquoted key breaks the whole document. Common errors our formatter catches and auto-repairs:
- Trailing commas — valid in JavaScript objects, invalid in JSON.
{"a":1,}fails. - Single quotes — JSON requires double quotes.
{'a':1}fails. - Unquoted keys — all keys must be strings with double quotes.
{a:1}fails. - JavaScript comments —
// commentand/* block */are not valid JSON. - Undefined / NaN / Infinity — these are JavaScript values, not JSON. Use
nullor omit. - Hex / octal / binary numbers — only decimal numbers allowed.
- Unescaped control characters — newlines, tabs, etc. inside string values must be escaped with
\n,\t.
Click "Fix & Format" to apply all of these in one pass. Underlying this is JSON5-style parsing that's lenient on input and strict on output.
JSON vs JSON5 vs JSONC vs NDJSON — which should you use?
The JSON family has spawned several dialects. Short guide:
| Format | Allows | Use for |
|---|---|---|
| JSON (RFC 8259) | strict only | API payloads, data storage, wire format |
| JSON5 | comments, trailing commas, unquoted keys, single quotes, hex numbers | Human-edited config files |
| JSONC (JSON with Comments) | line + block comments, trailing commas | tsconfig.json, devcontainer.json — VS Code ecosystem |
| NDJSON / JSON Lines | one valid JSON object per line, newline-delimited | Streaming data, log files, ML training data |
| HJSON | comments, unquoted strings, Ruby-like syntax | Rarely seen; JSON5 won |
For APIs: always produce strict JSON. For config you write by hand: JSONC or JSON5. For logs / event streams: NDJSON (one complete JSON per line means you can grep and split without a full-file parse).
Minify vs beautify — when to use each
Beautify (also called "pretty-print" or "format"): adds indentation and line breaks. Makes JSON readable for humans. Increases file size by 30-60%.
Minify: removes all whitespace. Smaller file, faster to transmit, harder to read. Useful for production API responses, payload size optimization, embedding JSON in source code.
# Beautified (readable)
{
"user": "alice",
"email": "alice@example.com",
"roles": [
"admin",
"editor"
]
}
# Minified (compact)
{"user":"alice","email":"alice@example.com","roles":["admin","editor"]}
Typical production pattern: minify for HTTP responses, beautify before storing in git. Our formatter toggles between the two in one click and preserves the underlying data exactly — no key order changes, no type coercion.
Frequently Asked Questions
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate.
How do I fix invalid JSON?
Common issues include trailing commas, single quotes instead of double quotes, unquoted property names, and JavaScript comments. Our Fix & Format feature automatically repairs these.
What's the difference between minify and beautify?
Beautify adds indentation and line breaks for readability. Minify removes all whitespace to reduce file size, useful for production deployments.