What "valid JSON" actually means
JSON (JavaScript Object Notation) is a strict, minimal data format — much stricter than JavaScript object literals. Every key must be wrapped in double quotes (never single quotes), strings can't have trailing commas after the last item, and comments aren't allowed at all. Most "invalid JSON" errors come from one of these three habits carried over from writing regular JavaScript.
Reading the error location
When your JSON doesn't parse, the error message includes a line and column number pointing to where the parser gave up — which is usually right at, or just after, the actual mistake. A common gotcha: if you're missing a closing brace or bracket, the error often points to the very end of the file rather than where the unclosed one started, since that's where the parser finally ran out of input.
Format vs. minify — when to use each
- Format (pretty-print) — for reading, debugging, or committing to a repo where humans review diffs.
- Minify — for pasting into a config field, environment variable, or API payload where every byte counts and no one needs to read it directly.
Example
Invalid (trailing comma, single-quoted key):
{ 'name': "Alex", "age": 30, }
Valid, formatted:
{
"name": "Alex",
"age": 30
}