Contents
array_to_json()
A function for converting an array to JSON
array_to_json()
is a system function for converting an array to JSON representation.
array_to_json()
was added in PostgreSQL 9.2.
Usage
array_to_json (anyarray
[,boolean
] ) →json
If the optional boolean
parameter is set to TRUE
, line breaks will be added between top-level array elements.
Change history
- PostgreSQL 9.2
- added (commit 39909d1d)
Examples
Basic usage examples for array_to_json()
:
postgres=# SELECT array_to_json(ARRAY[1,2,3]); array_to_json --------------- [1,2,3] (1 row) postgres=# SELECT array_to_json(ARRAY[ [1,2,3],[4,5,6] ]); array_to_json ------------------- [[1,2,3],[4,5,6]] (1 row) postgres=# SELECT array_to_json(ARRAY[ [1,2,3],[4,5,6] ], TRUE); array_to_json --------------- [[1,2,3], + [4,5,6]] (1 row)
References
- PostgreSQL documentation: JSON Creation Functions
Categories
See also
array_to_string(), array_to_tsvector(), row_to_json(), hstore_to_json(), row_to_json()