PostgreSQL jsonb_object_keys() Function
The PostgreSQL jsonb_object_keys()
function returns a set of keys in the specified top-level JSONB object.
jsonb_object_keys()
Syntax
This is the syntax of the PostgreSQL jsonb_object_keys()
function:
jsonb_object_keys(any_object JSONB) -> SETOF TEXT
Parameters
any_object
-
Required. A JSONB object.
Return value
The PostgreSQL jsonb_object_keys()
function returns a set ( SETOF
) of text that contains all the top-level keys in the specified JSONB object.
jsonb_object_keys()
Examples
This example shows how to use the PostgreSQL jsonb_object_keys()
function to get all the top-level keys of a JSONB object.
SELECT jsonb_object_keys('{"name": "Tom", "age": 20, "hobbies": ["sports", "cars"]}');
jsonb_object_keys
------------------
name
age
hobbies
Since the jsonb_object_keys()
function return value is of type SETOF
, you can use jsonb_object_keys()
in the SELECT * FROM
statement:
SELECT
*
FROM
jsonb_object_keys('{"name": "Tom", "age": 20, "hobbies": ["sports", "cars"]}')
AS x(keys);
keys
---------
name
age
hobbies