Skip to content

Getting Comfortable · Valid vs Invalid JSON

All tutorials

Valid vs Invalid JSON

Invalid JSON will cause parsing to fail. Common errors: forgetting quotes, using single quotes, trailing commas, or JavaScript-only values like undefined or NaN (which aren't valid JSON).

// ✅ Valid
{"a": 1, "b": [2, 3]}

// ❌ Trailing comma
{"a": 1, "b": 2,}

// ❌ Single quotes (JavaScript OK, JSON invalid)
{'a': 1}

// ❌ Unquoted key
{a: 1}

// ❌ undefined is not valid JSON
{"a": undefined}