Outdated Version

You are viewing an older version of this section. View current production version.

JSON_GET_TYPE

Returns the Javascript type of the given JSON object.

JSON_GET_TYPE(json)

Arguments

  • json: a valid JSON value.
  • keyname: the named key to extract.

Return Type

The type is returned as one of the following strings:

  • “double”
  • “string”
  • “boolean”
  • “null”
  • “object”
  • “array”
  • Or, SQL NULL if json is not a valid JSON object.

Examples

mysql> select json_get_type('true');
+-----------------------+
| json_get_type('true') |
+-----------------------+
| boolean               |
+-----------------------+

mysql> select json_get_type('12345');
+------------------------+
| json_get_type('12345') |
+------------------------+
| double                 |
+------------------------+

mysql> select json_get_type('"ohai"');
+-------------------------+
| json_get_type('"ohai"') |
+-------------------------+
| string                  |
+-------------------------+

mysql> select json_get_type('[1,2,3]');
+--------------------------+
| json_get_type('[1,2,3]') |
+--------------------------+
| array                    |
+--------------------------+

mysql> select json_get_type('{"a":1, "b":2}');
+---------------------------------+
| json_get_type('{"a":1, "b":2}') |
+---------------------------------+
| object                          |
+---------------------------------+

mysql> select json_get_type('null');
+-----------------------+
| json_get_type('null') |
+-----------------------+
| null                  |
+-----------------------+
Info

A JSON or Javascript null value is distinct from SQL NULL.