PostgreSQL JSON Functions
This page lists PostgreSQL JSON functions that perform operations on JSON values.
-
array_to_json
The PostgreSQLarray_to_json()function converts an SQL array to a JSON array and returns the JSON array. -
json_array_elements
The PostgreSQLjson_array_elements()function expands the top-level JSON array into a set of JSON values. -
json_array_elements_text
The PostgreSQLjson_array_elements_text()function expands the top-level JSON array into a set of text values. -
json_array_length
The PostgreSQLjson_array_length()function returns the length (the number of top-level elements in the array) of a specified JSON array. -
json_build_array
The PostgreSQLjson_build_array()function creates and returns a JSON array of possibly heterogeneous types from a variadic parameter list. -
json_build_object
The PostgreSQLjson_build_object()function creates and returns a JSON object from a variadic parameter list consisting of alternating keys and values. -
json_each
The PostgreSQLjson_each()function expands a specified JSON object into a set of key-value pairs (the keys are of type text and the values are of type JSON). -
json_each_text
Expands a top-level JSON object into rows with text keys and text values. -
json_extract_path
The PostgreSQLjson_extract_path()function extracts JSON nested value from a specified JSON value according to the specified path. -
json_extract_path_text
Extracts a JSON value by path components and returns it as text; missing paths yield NULL. -
json_object
The PostgreSQLjson_object()function builds a JSON object from a text array, or from two arrays as keys and values respectively. -
json_object_keys
The PostgreSQLjson_object_keys()function returns a set of keys in the specified top-level JSON object. -
json_populate_record
The PostgreSQLjson_populate_record()function converts the specified top-level JSON object to a specified SQL type value. -
json_populate_recordset
The PostgreSQLjson_populate_recordset()function converts the specified top-level JSON array to a set of specified SQL-typed values. -
json_strip_nulls
Recursively remove null-valued object fields from PostgreSQL json; PostgreSQL 18+ can also strip null array elements. -
json_to_record
The PostgreSQLjson_to_record()function expands the specified top-level JSON object into a row with the corresponding type defined in the AS clause. -
json_to_recordset
Expands a JSON array of objects into rows whose columns are declared in the query’s AS clause. -
json_typeof
The PostgreSQLjson_typeof()function returns the type of the specified JSON value as a string. -
jsonb_array_elements
The PostgreSQLjsonb_array_elements()function expands the top-level JSONB array into a set of JSONB values. -
jsonb_array_elements_text
The PostgreSQLjsonb_array_elements_text()function expands the top-level JSONB array into a set of text values. -
jsonb_array_length
The PostgreSQLjsonb_array_length()function returns the length (the number of top-level elements in the array) of a specified JSONB array. -
jsonb_build_array
The PostgreSQLjsonb_build_array()function creates and returns a JSONB array of possibly heterogeneous types from a variadic parameter list. -
jsonb_build_object
The PostgreSQLjsonb_build_object()function creates and returns a JSONB object from a variadic parameter list consisting of alternating keys and values. -
jsonb_each
Expands a top-level JSONB object into rows with a text key and a JSONB value. -
jsonb_each_text
Expands a top-level JSONB object into rows with text keys and text values. -
jsonb_extract_path
The PostgreSQLjsonb_extract_path()function extracts JSONB nested value from a specified JSONB value according to the specified path. -
jsonb_extract_path_text
Extracts a JSONB value by path components and returns it as text; missing paths yield NULL. -
jsonb_insert
Inserts JSONB before or after a path target; for object fields, it inserts only when the key is absent. -
jsonb_object
The PostgreSQLjsonb_object()function builds a JSONB object from a text array, or from two arrays as keys and values respectively. -
jsonb_object_keys
The PostgreSQLjsonb_object_keys()function returns a set of keys in the specified top-level JSONB object. -
jsonb_path_exists
The PostgreSQLjsonb_path_exists()function checks whether a specified path returns a value in a given JSON. -
jsonb_path_exists_tz
Checks whether a JSONPath expression returns any item, including paths that need time zone-aware date/time conversion. -
jsonb_path_match
The PostgreSQLjsonb_path_match()function returns the result of executing a JSON path assertion against a specified JSON value. -
jsonb_path_match_tz
Evaluates a JSONPath predicate to a SQL boolean, supporting date/time comparisons that need time zone-aware conversion. -
jsonb_path_query
The PostgreSQLjsonb_path_query()function fetches the values in a given JSON according to the specified path and returns all matching values as a set. -
jsonb_path_query_array
The PostgreSQLjsonb_path_query_array()fetches the values in a given JSON according to the specified path and returns all matching values as an array. -
jsonb_path_query_array_tz
Returns JSONPath matches as a JSONB array and supports date/time comparisons that need time zone-aware conversion. -
jsonb_path_query_first
The PostgreSQLjsonb_path_query_first()function gets the value in a given JSON according to the specified path and returns the first matching value. -
jsonb_path_query_first_tz
Returns the first JSONPath match as JSONB and supports date/time comparisons that need time zone-aware conversion. -
jsonb_path_query_tz
Returns all JSONPath matches as a set and supports date/time comparisons that need time zone-aware conversion. -
jsonb_populate_record
The PostgreSQLjsonb_populate_record()function converts the specified top-level JSONB object to a specified SQL type value. -
jsonb_populate_recordset
The PostgreSQLjsonb_populate_recordset()function converts the specified top-level JSONB array to a set of specified SQL-typed values. -
jsonb_pretty
The PostgreSQLjsonb_pretty()function uses whitespace indentation and newlines to convert a given JSONB value into a formatted, more readable text. -
jsonb_set
Replaces a JSONB value at a path or creates the final path item when it is missing andcreate_if_missingis true. -
jsonb_set_lax
Sets a JSONB value at a path and handles SQL NULL input by writing JSON null, deleting the key, raising an error, or returning the target. -
jsonb_strip_nulls
Recursively remove null-valued object fields from PostgreSQL jsonb and return jsonb; PostgreSQL 18+ can also strip null array elements. -
jsonb_to_record
The PostgreSQLjsonb_to_record()function expands the specified top-level JSONB object into a row with the corresponding type defined in theASclause. -
jsonb_to_recordset
Expands a JSONB array of objects into rows whose columns are declared in the query’s AS clause. -
jsonb_typeof
The PostgreSQLjsonb_typeof()function returns the type of the specified JSONB value as a string. -
row_to_json
The PostgreSQLrow_to_json()function converts a value of an SQL composite type to a JSON object and returns it. -
to_json
The PostgreSQLto_json()function converts a SQL value of to a JSON value and returns the result. -
to_jsonb
The PostgreSQLto_jsonb()function converts a SQL value to a JSONB value and returns the result.