PostgreSQL 18 reference · JSON Functions

PostgreSQL JSONB_TYPEOF() Function

Return the type of the top-level JSON value: object, array, string, number, boolean or null.

PostgreSQL 18 Since 9.4

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

jsonb_typeof(jsonb)

Parameters

ParameterDescription
jsonb A jsonb (or json) value.

Return value

text.

Examples

Types
SELECT jsonb_typeof('{"a":1}') AS a, jsonb_typeof('[1]') AS b, jsonb_typeof('"x"') AS c, jsonb_typeof('null') AS d;

Output

   a    |   b   |   c    |  d
--------+-------+--------+------
 object | array | string | null
(1 row)

Run this on your computer — see “Get Started” for setup.

A field's type
SELECT jsonb_typeof('{"price":9.5}'::jsonb -> 'price') AS price_type;

Output

 price_type
------------
 number
(1 row)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 9.4Added

In other languages

Was this page helpful?