PostgreSQL json_array_elements() Function
The PostgreSQL json_array_elements()
function expands the top-level JSON array into a set of JSON values.
json_array_elements()
Syntax
This is the syntax of the PostgreSQL json_array_elements()
function:
json_array_elements(any_array JSON) -> SETOF JSON
Parameters
any_array
-
Required. A JSON array.
Return value
The PostgreSQL json_array_elements()
function returns a set including all the top-level elements in the JSON array specified by the parameter.
json_array_elements()
Examples
This example shows how to use the PostgreSQL json_array_elements()
function to expand a JSON array into a set of JSON values.
SELECT json_array_elements('[1, 2, [3, 4]]');
json_array_elements
---------------------
1
2
[3, 4]
Since the json_array_elements()
function return value is of type SETOF
, you can use json_array_elements()
as a temporary table in the SELECT * FROM
statement:
SELECT * FROM json_array_elements('[1, 2, [3, 4]]');
value
--------
1
2
[3, 4]