Collections:
JSON_SCHEMA_VALID() - JSON Schema Validation
How to validate a JSON value against a JSON schema using the JSON_SCHEMA_VALID() function?
✍: FYIcenter.com
JSON_SCHEMA_VALID(schema, json) is a MySQL built-in function that
validates a JSON value against a given JSON schema.
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_VALID(@schema, @document);
-- +---------------------------------------+
-- | JSON_SCHEMA_VALID(@schema, @document) |
-- +---------------------------------------+
-- | 1 |
-- +---------------------------------------+
SELECT JSON_SCHEMA_VALID(@schema, '{"latitude": 63.444697}');
-- +-------------------------------------------------------+
-- | JSON_SCHEMA_VALID(@schema, '{"latitude": 63.444697}') |
-- +-------------------------------------------------------+
-- | 0 |
-- +-------------------------------------------------------+
Reference information of the JSON_SCHEMA_VALID() function:
JSON_SCHEMA_VALID(schema, json): int Returns 1 if the JSON schema meets all requirements defined in the JSON schema. Otherwise it returns 0. Arguments, return value and availability: schema: Required. The JSON schema to validate against. json: Required. The JSON value to be validated. int: Return value. The validation result, 0 or 1. Available since MySQL 8.0.
Related MySQL functions:
⇒ JSON_SCHEMA_VALIDATION_REPORT() - JSON Schema Validation Report
⇐ JSON_REPLACE() - Replacing JSON Child Members
2024-11-23, 1372🔥, 0💬
Popular Posts:
How To Use SQL*Plus Built-in Timers in Oracle? If you don't have a stopwatch/timer and want to measu...
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL? If a subquery is used in a UPDAT...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
How To Verify Your PHP Installation in MySQL? PHP provides two execution interfaces: Command Line In...
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...