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
Syntax
jsonb_typeof(jsonb)
Parameters
| Parameter | Description |
|---|---|
jsonb |
A jsonb (or json) value. |
Return value
text.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 9.4 | Added |
In other languages
JSON_TYPE()· SQLite
Related
JSONB_ARRAY_LENGTH()· Return the number of elements in a JSON array. Raises an error for objects and scalars.- SQL String Functions · tutorial