JSON Schema Validation vs JSON Syntax Validation
There are two levels of JSON validation:
- Syntax validation — Is this text valid RFC 8259 JSON? (Does it parse?)
- Schema validation — Does this JSON object match an expected structure? (Do all required fields exist with the right types?)
JSON Schema validation is the more powerful of the two — it can enforce field types, required properties, string formats, numeric ranges, and array constraints.
What JSON Schema Draft-07 Can Validate
required— enforce mandatory fieldstype— string, number, integer, boolean, object, array, nullformat— email, date-time, uri, uuidminimum/maximum— numeric range constraintsminLength/maxLength— string length constraintspattern— regex pattern matchingenum— allowed value enumeration
json
// JSON Schema (Draft-07)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["name", "email", "age"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0, "maximum": 150 }
}
}
// ✅ Valid Data
{ "name": "Alice", "email": "a@example.com", "age": 28 }
// ❌ Invalid Data (3 errors)
{ "name": "", "email": "not-an-email", "age": -5 }
// Error 1: name must be at least 1 character
// Error 2: email must match format "email"
// Error 3: age must be >= 0