Collections:
JSON_SCHEMA_VALIDATION_REPORT() - JSON Schema Validation Report
How to generate a validation report of a JSON value against a JSON schema using the JSON_SCHEMA_VALIDATION_REPORT() function?
✍: FYIcenter.com
JSON_SCHEMA_VALIDATION_REPORT(schema, json) is a MySQL built-in function that
returns a validation report of a JSON value against a given JSON schema.
The report itself is a JSON object.
For example:
SET @schema = '{
"id": "http://json-schema.org/geo",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A geographical coordinate",
"type": "object",
"properties": {
"latitude": {
"type": "number"
},
"longitude": {
"type": "number"
}
},
"required": ["latitude", "longitude"]
}';
SET @document = '{"latitude": 63.444697, "longitude": 10.445118}';
SELECT JSON_SCHEMA_VALIDATION_REPORT(@schema, @document);
-- +---------------------------------------------------+
-- | JSON_SCHEMA_VALIDATION_REPORT(@schema, @document) |
-- +---------------------------------------------------+
-- | {"valid": true} |
-- +---------------------------------------------------+
SELECT JSON_SCHEMA_VALIDATION_REPORT(@schema, '{"latitude": 63.444697}');
-- +-----------------------------------------------------------------------+
-- | JSON_SCHEMA_VALIDATION_REPORT(@schema, '{"latitude": 63.444697}') |
-- +-----------------------------------------------------------------------+
-- | {"valid": false, "reason": "The JSON document location '#' failed
requirement 'required' at JSON Schema location '#'",
"schema-location": "#",
"document-location": "#",
"schema-failed-keyword": "required"} |
-- +-----------------------------------------------------------------------+
Reference information of the JSON_SCHEMA_VALIDATION_REPORT() function:
JSON_SCHEMA_VALIDATION_REPORT(schema, json): report Returns a validation report of a JSON value against a given JSON schema. Arguments, return value and availability: schema: Required. The JSON schema to validate against. json: Required. The JSON value to be validated. report: Return value. The validation report as a JSON object. Available since MySQL 8.0.
Related MySQL functions:
⇒ JSON_SEARCH() - Searching String in JSON
⇐ JSON_SCHEMA_VALID() - JSON Schema Validation
2024-11-23, 1584🔥, 0💬
Popular Posts:
How To Connect ASP Pages to Oracle Servers in Oracle? If you are running Windows IIS Web server and ...
How To Calculate DATETIME Value Differences Using the DATEDIFF() Function in SQL Server Transact-SQL...
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL? Random numbers a...
How To Verify a User name with SQLCMD Tool in SQL Server? The quickest way to verify a user name in ...
How To Create a Table Index in Oracle? If you have a table with a lots of rows, and you know that on...