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