Back to Blog

Invalid JSON vs Valid JSON

15 Real Examples Developers Get Wrong

Understanding the difference between invalid JSON and valid JSON is crucial for every developer. Many developers make the same mistakes repeatedly, causing errors in their applications.

In this guide, we'll show you 15 real examples of invalid JSON vs valid JSON, explaining why each is wrong and how to fix it. Use our free JSON Validator to check your JSON instantly.

Comparison Table: Invalid ❌ vs Valid ✅

MistakeInvalid JSON ❌Valid JSON ✅Why It's Wrong
Single Quotes{'name': 'John'}{"name": "John"}JSON only accepts double quotes for strings
Trailing Comma{"name": "John", "age": 30,}{"name": "John", "age": 30}No trailing commas allowed before closing braces
Comments{// comment "name": "John"}{"name": "John"}JSON does not support comments
NaN Value{"price": NaN}{"price": null}NaN is not valid in JSON, use null instead
Infinity Value{"count": Infinity}{"count": null}Infinity is not valid in JSON
Unquoted Keys{name: "John"}{"name": "John"}All keys must be wrapped in double quotes
Undefined Value{"middleName": undefined}{"middleName": null}undefined is not valid in JSON, use null or omit
Missing Closing Brace{"users": [{"name": "John"}]{"users": [{"name": "John"}]}Every opening brace needs a closing brace
Unescaped Quotes{"message": "He said "Hello""}{"message": "He said \"Hello\""}Quotes inside strings must be escaped
Trailing Comma in Array[1, 2, 3,][1, 2, 3]No trailing commas in arrays
Function Value{"handler": function() {}}{"handler": null}Functions are not valid JSON values
Date Object{"date": new Date()}{"date": "2025-01-15T00:00:00.000Z"}Date objects must be converted to strings
Multiple Root Objects{"a": 1}{"b": 2}[{"a": 1}, {"b": 2}]JSON must have a single root object or array
Missing Comma{"name": "John" "age": 30}{"name": "John", "age": 30}Properties must be separated by commas
Octal Numbers{"code": 0123}{"code": 123}Octal notation is not valid in JSON

Detailed Examples

Single Quotes

❌ Invalid:

{'name': 'John'}

✅ Valid:

{"name": "John"}

Why: JSON only accepts double quotes for strings

Trailing Comma

❌ Invalid:

{"name": "John", "age": 30,}

✅ Valid:

{"name": "John", "age": 30}

Why: No trailing commas allowed before closing braces

Comments

❌ Invalid:

{// comment
"name": "John"}

✅ Valid:

{"name": "John"}

Why: JSON does not support comments

NaN Value

❌ Invalid:

{"price": NaN}

✅ Valid:

{"price": null}

Why: NaN is not valid in JSON, use null instead

Infinity Value

❌ Invalid:

{"count": Infinity}

✅ Valid:

{"count": null}

Why: Infinity is not valid in JSON

How to Validate JSON Instantly

💡 Quick Validation:

  1. Copy your JSON
  2. Paste it into our JSON Validator
  3. Get instant feedback on validity
  4. If invalid, use our JSON Fixer to repair it

Validate and Fix JSON Instantly

Use our free JSON Validator to check your JSON, and JSON Fixer to repair any errors automatically.

Validate JSON Now