JSON_SCHEMA_VALID
MySQL 8.0.17+ supports JSON_SCHEMA_VALID() to validate a JSON document against a JSON Schema. Use it in CHECK constraints.
MySQL 8.0.17+ supports JSON_SCHEMA_VALID() to validate a JSON document against a JSON Schema. Use it in CHECK constraints.
CREATE TABLE events (
id INT AUTO_INCREMENT PRIMARY KEY,
payload JSON,
CONSTRAINT chk_payload CHECK (
JSON_SCHEMA_VALID(
'{"type":"object","required":["type","timestamp"]}',
payload
)
)
);
JSON Schema validation in CHECK constraints enforces structure at the database level.