JSON_TYPE

Updated at:

Returns the data type of a JSON value.

Syntax

string|number|boolean|null|object|array json_type(<json>)

Parameter

json: Required. The JSON expression.

Return value

Returns a STRING value.

Examples

  • Example 1: Returns the data type of a JSON array.

    select json_type(json '[{"a":1}, 23]');

    The following result is returned:

    +-----+
    | _c0 |
    +-----+
    | array |
    +-----+
  • Example 2: Returns the data type of a JSON number.

    select json_type(json '123');

    The following result is returned:

    +-----+
    | _c0 |
    +-----+
    | number |
    +-----+
  • Example 3: Returns the data type of a JSON string.

    select json_type(json '"123"');

    The following result is returned:

    +-----+
    | _c0 |
    +-----+
    | string |
    +-----+

Related functions

JSON_TYPE is a complex type function. For more information about functions that process complex data types, such as ARRAY, MAP, STRUCT, and JSON, see Complex type functions.