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
The PostgreSQLjson_each_text()
function expands a specified top-level member of a JSON object into a collection of key-value pairs (both keys and values are of type text). -
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
The PostgreSQLjson_extract_path_text()
function extracts JSON sub-objects according to the specified path from a specified JSON object and returns the result as text. -
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
The PostgreSQLjson_strip_nulls()
function removes fields with null values in the specified JSON object recursively, and null values in non-object fields are not processed. -
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
The PostgreSQLjson_to_recordset()
function expands the specified top-level JSON array (its elements are objects) into a set of rows with the type defined in the 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
The PostgreSQLjsonb_each()
function expands a specified JSONB object into a set of key-value pairs (the keys are of type text and the values are of type JSONB). -
jsonb_each_text
The PostgreSQLjsonb_each_text()
function expands a specified top-level member of a JSONB object into a collection of key-value pairs (both keys and values are of type text). -
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
The PostgreSQLjsonb_extract_path_text()
function extracts JSONB sub-objects according to the specified path from a specified JSONB object and returns the result as text. -
jsonb_insert
The PostgreSQLjsonb_insert()
function inserts a new value into a given JSONB value at the specified path. -
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
The PostgreSQLjsonb_path_exists_tz()
function checks whether a specified path returns a value in a given JSON. This function differs fromjsonb_path_exists()
in that it provides support for date/time with time zones. -
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
The PostgreSQLjsonb_path_match_tz()
function returns the result of executing a JSON path assertion against a specified JSON value. This function differs fromjsonb_path_match()
in that it provides support for date/time with time zones. -
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
The PostgreSQLjsonb_path_query_array_tz()
function fetches the values in a given JSON according to the specified path and returns all matching values as an array. This function differs fromjsonb_path_query_array_tz()
in that it provides support for date/time with time zones. -
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
The PostgreSQLjsonb_path_query_first_tz()
function gets the value in a given JSON according to the specified path and returns the first matching value. This functionjsonb_path_query_first()
differs from in that it provides support for date/time with time zones. -
jsonb_path_query_tz
The PostgreSQLjsonb_path_query_tz()
function fetches the values in a given JSON according to the specified path and returns all matching values as a set. This functionjsonb_path_query()
differs from in that it provides support for date/time with time zones. -
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
The PostgreSQLjsonb_set()
function replaces or inserts the value at the specified path. -
jsonb_set_lax
The PostgreSQLjsonb_set_lax()
function replaces or inserts the value at the specified path. This function differs fromjsonb_set()
in the method of handling NULL values. -
jsonb_strip_nulls
The PostgreSQLjsonb_strip_nulls()
function removes fields with null values in the specified JSONB object recursively, and null values in non-object fields are not processed. -
jsonb_to_record
The PostgreSQLjsonb_to_record()
function expands the specified top-level JSONB object into a row with the corresponding type defined in theAS
clause. -
jsonb_to_recordset
The PostgreSQLjsonb_to_recordset()
function expands the specified top-level JSONB array (its elements are objects) into a set of rows with the conforming type defined in the 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.