JSON_EXISTS_PATH
Descriptionβ
It is used to judge whether the field specified by json_path exists in the JSON data. If it exists, it returns TRUE, and if it does not exist, it returns FALSE
Syntaxβ
JSON_EXISTS_PATH (<json_str>, <path>)
Aliasβ
- JSONB_EXISTS_PATH
Parametersβ
Parameter | Description |
---|---|
<json_str> | The element to be included in the JSON array. It can be a value of any type, including NULL. If no element is specified, an empty array is returned. |
<path> | The JSON path to be judged. If it is NULL, then return NULL. |
Return Valuesβ
If it exists, return TRUE; if it does not exist, return FALSE.
Examplesβ
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.name');
+---------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.name') |
+---------------------------------------------------------------------------+
| 1 |
+---------------------------------------------------------------------------+
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
+--------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
+--------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------+
SELECT JSONB_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
+--------------------------------------------------------------------------+
| jsonb_exists_path(cast('{"id": 123, "name": "doris"}' as JSON), '$.age') |
+--------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------+