12.18.7 JSON Schema Validation FunctionsJSON模式验证函数

Beginning with MySQL 8.0.17, MySQL supports validation of JSON documents against JSON schemas conforming to Draft 4 of the JSON Schema specification. 从MySQL 8.0.17开始,MySQL支持根据符合JSON模式规范草案4的JSON模式验证JSON文档。This can be done using either of the functions detailed in this section, both of which take two arguments, a JSON schema, and a JSON document which is validated against the schema. 这可以使用本节中详述的函数中的任何一个来完成,这两个函数都有两个参数,一个是JSON模式,另一个是根据模式验证的JSON文档。JSON_SCHEMA_VALID() returns true if the document validates against the schema, and false if it does not; JSON_SCHEMA_VALIDATION_REPORT() provides a report in JSON format on the validation.JSON_SCHEMA_VALID()如果文档根据模式进行验证,则返回true,否则返回falseJSON_SCHEMA_VALIDATION_REPORT()提供一个JSON格式的验证报告。

Both functions handle null or invalid input as follows:这两个函数都处理空或无效输入,如下所示:

MySQL supports the required attribute in JSON schemas to enforce the inclusion of required properties (see the examples in the function descriptions).MySQL支持JSON模式中的required属性来强制包含所需的属性(参见函数描述中的示例)。

MySQL supports the id, $schema, description, and type attributes in JSON schemas but does not require any of these.MySQL支持JSON模式中的id$schemadescriptiontype属性,但不需要这些属性。

MySQL does not support external resources in JSON schemas; using the $ref keyword causes JSON_SCHEMA_VALID() to fail with ER_NOT_SUPPORTED_YET.MySQL不支持JSON模式中的外部资源;使用$ref关键字会导致JSON_SCHEMA_VALID()产生ER_NOT_SUPPORTED_YET失败。

Note注意

MySQL supports regular expression patterns in JSON schema, which supports but silently ignores invalid patterns (see the description of JSON_SCHEMA_VALID() for an example).MySQL支持JSON schema中的正则表达式模式,它支持但默默地忽略无效模式(参见JSON_SCHEMA_VALID()的描述)。

These functions are described in detail in the following list:下面的列表详细描述了这些功能: