Why Is My JSON Invalid? 10 Common JSON Errors Explained
Explore the 10 most common JSON syntax errors with examples, learn why parsers reject them, and discover how to find and fix them in seconds.
“This looks completely correct. Why is it still failing?”
Have you ever looked at a JSON document and been 100% sure it was valid, only to have your backend, browser, or API client crash with a cryptic SyntaxError: Unexpected token?
JSON has a simple grammar, but it has no room for forgiveness. A single missing comma, an accidental trailing comma, single quotes from a copy-paste, or smart typographic quotes will cause a JSON parser to reject the entire payload.
In this guide, we break down the 10 most common JSON errors, explain the exact parser mechanics behind them, and show you how to find and fix them in seconds.
10 Errors Covered in This Guide:
Missing Commas Between Properties
Forgetting a comma between keys or array items causes unexpected token errors.
1{2 "name": "John"3 "age": 254}1{2 "name": "John",3 "age": 254}A comma separates key-value pairs and array items, but never put one after the final item.
Using Single Quotes (') Instead of Double Quotes (")
Common when copying JavaScript or Python code. Standard JSON strictly requires double quotes.
1{2 'name': 'John',3 'age': 254}1{2 "name": "John",3 "age": 254}Strings and property keys must always be enclosed in standard double quotes (").
Unquoted Property Names
In JavaScript object literals, key quotes are optional. In JSON, unquoted keys are invalid.
1{2 name: "John",3 age: 254}1{2 "name": "John",3 "age": 254}Every key name must be wrapped in double quotes.
Trailing Commas After Final Items
Leaving a comma after the last property in an object or array breaks RFC 8259 syntax.
1{2 "name": "John",3 "age": 25,4}1{2 "name": "John",3 "age": 254}Never place a comma after the final property or array element.
Missing or Extra Brackets ({ } and [ ])
Deeply nested structures often leave unclosed brackets or mismatched curly/square braces.
1{2 "user": {3 "name": "John",4 "age": 255 }1{2 "user": {3 "name": "John",4 "age": 255 }6}Every opening { must match a closing }, and every [ must match a closing ].
Invalid Backslash Escape Sequences
Backslashes are reserved for escapes (\n, \t, \", \\). Naked backslashes like \w fail.
1{2 "message": "Hello\world"3}1{2 "message": "Hello\\world"3}To render a literal backslash, escape it with a double backslash (\\).
Using JavaScript-Specific Values (undefined, NaN)
JSON does not support undefined, functions, Symbols, or Date objects.
1// JavaScript (INVALID in JSON)2{3 "name": "John",4 "email": undefined5}1{2 "name": "John",3 "email": null4}Use null to represent empty or missing values instead of undefined.
Capitalized Booleans and Null (True, FALSE, NULL)
Python or SQL developers often write True or NULL. JSON literals are strictly lowercase.
1{2 "active": True,3 "verified": FALSE,4 "address": NULL5}1{2 "active": true,3 "verified": false,4 "address": null5}Always write booleans and null in strict lowercase: true, false, null.
Accidentally Using JSON5 Syntax in Standard JSON
Comments (//, /* */) and single quotes work in JSON5 and tsconfig, but crash JSON.parse().
1// Valid in JSON5, INVALID in Standard JSON:2{3 // User comments are allowed4 name: 'John',5 age: 25,6}1{2 "name": "John",3 "age": 254}Standard JSON forbids comments, unquoted keys, and single quotes.
Extra Text Outside the JSON Document
Pasting log prefixes ("Response: { ... }") or markdown code fences into parsers.
1Here is the response:23{4 "name": "John"5}1{2 "name": "John"3}The document must start with { or [ and contain nothing else before or after.
Bonus: The “Looks Fine” Problem (Smart Quotes)
Some JSON errors are invisible to the naked eye because the characters look nearly identical. The most notorious example is typographic curly quotes (smart quotes):
1{2 “name”: “John”3}Contains unicode characters “ (U+201C) and ” (U+201D).
1{2 "name": "John"3}Contains standard ASCII character " (U+0022).
Why Does JSON Fail So Easily?
JSON's strictness is completely intentional. Douglas Crockford designed JSON in 2001 to be a universal, language-agnostic data interchange format.
In a programming language like JavaScript or Python, flexibility allows for faster coding. However, for machine-to-machine data exchange where a Python server communicates with a Go microservice and a React client, ambiguity is disastrous.
By enforcing rigid rules—double quotes only, no trailing commas, no unquoted keys—every programming language on Earth can parse JSON using the exact same predictable parser algorithm without guessing the developer's intent.
How to Debug Invalid JSON in 6 Fast Steps
When a parser crashes, never scan blindly through thousands of lines. Follow this systematic diagnostic routine:
Format the JSON
Turn single-line minified JSON into an indented hierarchy. Formatting reveals structure and missing punctuation instantly.
Validate Syntax with a Tool
Don’t guess. Paste the JSON into a dedicated validator to pinpoint the exact line, column, and character causing the error.
Check Right Before the Error Line
Parsers often flag the token AFTER the real problem (e.g., flagging line 4 because line 3 was missing a comma).
Inspect Quotation Marks
Check for single quotes ('), backticks (`), or typographic “smart quotes” copied from chat/docs.
Scan Commas and Trailing Commas
Verify that every property has a comma except the very last one before the closing } or ].
Match Brackets from Outside-In
Ensure every { has a matching } and every [ has a matching ]. Nested formatting makes this obvious.
Practical Challenge: Spot the 2 Hidden Bugs
This snippet looks clean and readable, but running JSON.parse() on it will immediately fail. Can you spot both errors?
1{2 "user": {3 "name": 'John',4 "age": 25,5 "skills": [6 "JavaScript",7 "Python",8 ]9 }10}Look closely at line 3 and line 7.
JSON Syntax Error vs. JSON Data Error
Many developers confuse structural syntax errors with application semantic data errors. Here is why the distinction matters:
1{2 "name": "John"3 "age": 254}The file violates RFC 8259 grammar (missing comma). The parser halts immediately before any data can be extracted or read.
1{2 "age": "twenty-five" // Valid syntax, but application expects number!3}The JSON itself parses cleanly into memory. However, the application crashes later when doing mathematical calculations because age was a string rather than a number.
Interactive Pre-Send JSON Syntax Checklist
Before pushing a payload to an external API or saving a configuration file, run through this quick 11-point inspection:
JavaScript Object vs. JSON: Don't Mix Them Up
A massive percentage of daily JSON errors happen because frontend developers confuse JavaScript code with JSON strings. JavaScript allows unquoted keys, single quotes, trailing commas, and comments; JSON permits none of these.
1// JavaScript Object Literal2const user = {3 name: 'John',4 age: 25,5 isActive: true,6};1{2 "name": "John",3 "age": 25,4 "isActive": true5}Format → Validate → Locate → Fix → Validate Again
When JSON looks right but still fails, let an automated validator do the heavy lifting instead of burning mental energy searching for a missing comma.