How to Create a CHECK Constraint Against a JSON Column in MySQL

When we create or modify a table in MySQL, we have the option of applying a CHECK constraint against one or more columns. This allows us to check the data before it enters the database. Data can only enter the database if it doesn’t violate the rules in our CHECK constraint.

If the column is a JSON column, we have the option of creating a CHECK constraint that checks that the JSON document doesn’t violate its JSON schema. To do this, we can include the schema in the CHECK constraint.

Continue reading

Understanding the JSON_SCHEMA_VALIDATION_REPORT() Function in MySQL

In MySQL, the JSON_SCHEMA_VALIDATION_REPORT() function validates a JSON document against a JSON schema and returns a report of the outcome of that validation. The report is returned as a JSON document.

If the document is valid, only one field is returned: "valid" : true. If the document is not valid, a more extensive report is provided.

Continue reading