PostgreSQL jsonb_typeof() Function

The PostgreSQL jsonb_typeof() function returns the type of the specified JSONB value as a string.

jsonb_typeof() Syntax

This is the syntax of the PostgreSQL jsonb_typeof() function:

jsonb_typeof(json_value JSONB) -> TEXT

Parameters

json_value

Required. The JSONB value to detect.

Return value

The PostgreSQL jsonb_typeof() function returns a text string that is the type of the specified JSONB value. Possible returned values are: object, array, string, number, boolean and null.

If you provide a NULL parameter, the jsonb_typeof() function will return NULL.

jsonb_typeof() Examples

This example shows how to use the PostgreSQL jsonb_typeof() function to return the type of a JSONB value.

SELECT
  jsonb_typeof('"abc"') AS "abc",
  jsonb_typeof('123.45') AS "123.45",
  jsonb_typeof('true') AS "true",
  jsonb_typeof('false') AS "false",
  jsonb_typeof('[1,2,3]') AS "[1,2,3]",
  jsonb_typeof('{"x":1}') AS "{""x"":1}",
  jsonb_typeof('null') AS "null";
  abc   | 123.45 |  true   |  false  | [1,2,3] | {"x":1} | null
--------+--------+---------+---------+---------+---------+------
 string | number | boolean | boolean | array   | object  | null

If you provide a NULL parameter, the jsonb_typeof() function will return NULL. E.g:

SELECT jsonb_typeof(NULL) IS NULL AS "jsonb_typeof(NULL) IS NULL";
 jsonb_typeof(NULL) IS NULL
---------------------------
 t