JSON_TYPE()

All functions > JSON > JSON_TYPE()

Returns the type of a JSON value as a string.

Signatures

Returns: The JSON type name (e.g. 'OBJECT', 'ARRAY', 'STRING', 'NUMBER', 'BOOLEAN', 'NULL')

JSON_TYPE(expr: JSON) → VARCHAR
sql
ParameterTypeRequiredDescription
exprJSONYesThe JSON expression to inspect

Notes

  • Returns the JSON kind of the top-level value: OBJECT, ARRAY, STRING, NUMBER, BOOLEAN, or NULL
  • JSON null is a value, so its kind is the string 'NULL', never SQL NULL
  • Returns NULL if the input is SQL NULL
  • Useful for branching logic on polymorphic JSON columns
  • Use with JSON_EXTRACT to check the type of nested values

Availability

Available on DuckDB. Not available on Trino, Serving.

See also

Examples

Edge cases

FeatureQL
RETURN
    -- Object type
    f1 := JSON_TYPE(JSON_PARSE('{"a": 1}')),
    -- Array type
    f2 := JSON_TYPE(JSON_PARSE('[1, 2]')),
    -- String type
    f3 := JSON_TYPE(JSON_PARSE('"hello"')),
    -- Number type
    f4 := JSON_TYPE(JSON_PARSE('42')),
    -- Boolean type
    f5 := JSON_TYPE(JSON_PARSE('true'))
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHAR
OBJECTARRAYSTRINGNUMBERBOOLEAN