Checks whether the JSON value in a specific JSON path exist.
Syntax
boolean json_exists(<json>, <json_path>)
Parameters
json: required. This parameter specifies the JSON expression that you want to process.
json_path: required. This parameter 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 '[1,2, {"a":34}]', '$[2].a');
The following result is returned:
+------+ | _c0 | +------+ | true | +------+
Example 3: Check whether values that are obtained based on a specific subscript exist.
select json_exists(json '{"a":1, "b":2}', 'strict $.c');
The following result is returned:
+------+ | _c0 | +------+ | false | +------+
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.