PostgreSQL json_typeof() Function

The PostgreSQL json_typeof() function returns the type of the specified JSON value as a string.

json_typeof() Syntax

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

json_typeof(json_value JSON) -> TEXT

Parameters

json_value

Required. The JSON value to detect.

Return value

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

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

json_typeof() Examples

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

SELECT
  json_typeof('"abc"') AS "abc",
  json_typeof('123.45') AS "123.45",
  json_typeof('true') AS "true",
  json_typeof('false') AS "false",
  json_typeof('[1,2,3]') AS "[1,2,3]",
  json_typeof('{"x":1}') AS "{""x"":1}",
  json_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 json_typeof() function will return NULL. E.g:

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