What makes JSON valid?
A JSON document is valid when it follows the rules of the JSON specification (RFC 8259). There are two levels of correctness:
- Syntax validity — the text is well-formed JSON: correct brackets, quoted keys, no trailing commas, no comments.
- Schema validity — the data has the expected structure: required fields exist, values have the right type, numbers are within allowed ranges.
A JSON parser validates syntax. JSON Schema validates structure. Both matter — but you need syntax to be valid first.
Common JSON errors
These are the mistakes that most often break JSON documents:
{
"name": "Jane",
"age": 30,
}{
"name": "Jane",
"age": 30
}The comma after the last property is illegal in JSON. JavaScript allows it — JSON does not.
{'name': 'Jane'}{"name": "Jane"}JSON requires double quotes for both keys and string values. Single quotes are a JavaScript convenience, not valid JSON.
{name: "Jane", age: 30}{"name": "Jane", "age": 30}All object keys must be quoted strings. This is the most common mistake for developers coming from JavaScript object literals.
{
"timeout": 30 // seconds
}{
"timeout": 30
}JSON has no comment syntax. Remove comments before parsing, or switch to JSONC / YAML for config files that need documentation.
{"value": undefined, "ratio": NaN}{"value": null, "ratio": 0}JSON only allows: string, number, boolean, null, object, array. undefined, NaN, and Infinity are JavaScript values with no JSON equivalent.
JSON syntax rules — quick reference
"hello"'hello'"key": 1key: 1[1, 2, 3][1, 2, 3,]"x": null"x": undefinedtrue / falseTrue / False3.14.14 or 01{} or []bare stringValidate JSON in code
Every major language has a built-in JSON parser. Wrap the parse call in a try/catch to validate:
JavaScript / Node.js
try { const data = JSON.parse(str) console.log('Valid JSON', data) } catch (e) { console.error('Invalid JSON:', e.message) }Python
import json try: data = json.loads(s) print('Valid JSON', data) except json.JSONDecodeError as e: print('Invalid JSON:', e)PHP
$data = json_decode($str, true); if (json_last_error() !== JSON_ERROR_NONE) { echo 'Invalid JSON: ' . json_last_error_msg(); }Go further with JSON Schema
Syntax validation only checks that the JSON is parseable. JSON Schema lets you validate the content — required fields, value types, formats, and ranges.
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "required": ["name", "age", "email"], "properties": { "name": { "type": "string", "minLength": 1 }, "age": { "type": "integer", "minimum": 0, "maximum": 150 }, "email": { "type": "string", "format": "email" } } }With this schema, {"name": "Jane", "age": -5, "email": "jane@example.com"} would fail validation because age is below the minimum of 0 — even though it's perfectly valid JSON syntax.