Skip to main content
Returns the type of a JSON value as a string: 'null', 'boolean', 'number', 'string', 'array', or 'object'. Returns NULL if the input is NULL. The argument may be either a native JSON value (which is inspected directly, without re-parsing) or a TEXT value containing a JSON document (which is parsed).

Syntax

JSON_TYPEOF(<json>)

Aliases

JSONB_TYPEOF(<json>)

Parameters

ParameterDescriptionSupported input types
<json>The JSON value whose type is reported.JSON, TEXT

Return Type

The JSON_TYPEOF function returns a result of type TEXT.

Remarks

When the argument is a native JSON value it is already validated, so the type is determined directly from the stored representation. When the argument is TEXT, the input is parsed and an error is raised if it is not valid JSON.

Examples

The following examples report the type of each native JSON value:
SELECT JSON_TYPEOF('{"a": 1}'::JSON);   -- Returns 'object'
SELECT JSON_TYPEOF('[1, 2, 3]'::JSON);  -- Returns 'array'
SELECT JSON_TYPEOF('"hello"'::JSON);    -- Returns 'string'
SELECT JSON_TYPEOF('42'::JSON);         -- Returns 'number'
SELECT JSON_TYPEOF('true'::JSON);       -- Returns 'boolean'
SELECT JSON_TYPEOF('null'::JSON);       -- Returns 'null'
The argument can also be a TEXT value containing a JSON document, which is parsed before its type is reported:
SELECT JSON_TYPEOF('[1, 2, 3]'::TEXT);  -- Returns 'array'