Purpose
JSON_TYPE() returns a utf8mb4 string that indicates the type of a JSON value.
Syntax
JSON_TYPE(json_val)
Description
The value of json_val can be an object, an array, or a scalar type.
If the argument is NULL, NULL is returned. If the argument is not a valid JSON value, an error is returned.
Examples
obclient> SET @jn = '{"a": [10, true]}';
Query OK, 0 rows affected
obclient> SELECT JSON_TYPE(JSON_EXTRACT(@jn, '$.a'));
+-------------------------------------+
| JSON_TYPE(JSON_EXTRACT(@jn, '$.a')) |
+-------------------------------------+
| ARRAY |
+-------------------------------------+
1 row in set
obclient> SELECT JSON_TYPE(JSON_EXTRACT(@jn, '$.a[0]'));
+----------------------------------------+
| JSON_TYPE(JSON_EXTRACT(@jn, '$.a[0]')) |
+----------------------------------------+
| INTEGER |
+----------------------------------------+
1 row in set
obclient> SELECT JSON_TYPE(JSON_EXTRACT(@jn, '$.a[1]'));
+----------------------------------------+
| JSON_TYPE(JSON_EXTRACT(@jn, '$.a[1]')) |
+----------------------------------------+
| BOOLEAN |
+----------------------------------------+
1 row in set
obclient> SELECT JSON_TYPE(NULL);
+-----------------+
| JSON_TYPE(NULL) |
+-----------------+
| NULL |
+-----------------+
1 row in set
obclient> SELECT JSON_TYPE(1);
ERROR 3146 (22032): Invalid data type for JSON data in argument 1
to function json_type; a JSON string or JSON type is required.