JSON_EXISTS_PATH
Descriptionβ
Used to determine whether the field specified by <path>
exists in JSON data. Returns TRUE if it exists, FALSE if it does not exist.
Syntaxβ
JSON_EXISTS_PATH (<json_object>, <path>)
Parametersβ
<json_object>
JSON type, determine whether the path specified by<path>
exists in it.<path>
String type, specifies the path.
Return Valueβ
- BOOL type, returns TRUE if it exists, FALSE if it does not exist
- NULL: If either
<json_object>
or<path>
is NULL, returns NULL.
Examplesβ
- Example 1
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.name');
+------------------------------------------------------------+
| JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.name') |
+------------------------------------------------------------+
| 1 |
+------------------------------------------------------------+ - Example 2
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age');
+-----------------------------------------------------------+
| JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', '$.age') |
+-----------------------------------------------------------+
| 0 |
+-----------------------------------------------------------+ - NULL parameters
SELECT JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', NULL);
+--------------------------------------------------------+
| JSON_EXISTS_PATH('{"id": 123, "name": "doris"}', NULL) |
+--------------------------------------------------------+
| NULL |
+--------------------------------------------------------+SELECT JSON_EXISTS_PATH(NULL, '$.age');
+---------------------------------+
| JSON_EXISTS_PATH(NULL, '$.age') |
+---------------------------------+
| NULL |
+---------------------------------+