Checks whether the JSON value in a specific JSON path exist.
Syntax
BOOLEAN JSON_EXISTS(<json>, <json_path>)Parameters
Parameter | Required | Description |
json | Yes | Specifies the JSON expression to process. |
json_path | Yes | Specifies the JSON path in which a specific JSON value is checked. |
If the JSON path that you specify is invalid, an error is reported. In strict mode, if the structure of JSON data in a JSON path is inconsistent with the actual structure of JSON data, no error is reported, and the JSON_EXISTS function returns false.
Return value
The return value is true or false, which is of the BOOLEAN type.
Examples
Example 1: Check whether the value of the key 'a' exists in a JSON object.
SELECT JSON_EXISTS(JSON '{"a":1, "b":2}', '$.a');The following result is returned:
+------+ | _c0 | +------+ | true | +------+Example 2: Check whether the value of the key 'c' exists in a JSON object.
SELECT JSON_EXISTS(JSON '{"a":1, "b":2}', '$.c');The following result is returned:
SELECT JSON_EXISTS(JSON '{"a":1, "b":2}', '$.c');Example 3: Check whether values that are obtained based on a specific subscript exist.
SELECT JSON_EXISTS(JSON '[1,2, {"a":34}]', '$[2].a');The following result is returned:
+------+ | _c0 | +------+ | true | +------+
Related functions
JSON_EXISTS is a complex type function. For more information about the functions that are used to process data of complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.