PostgreSQLยฎ offers two types of data types to handle JSON data, JSON
and JSONB
, you can use the function array_to_json
(array_to_jsonb
for JSONB
) to create a JSON array from an existing array.
NOTE: To review the differences between
JSON
andJSONB
check out the related article.
NOTE: more info is available in the PostgreSQL JSON functions documentation page
ย
๐ Need a FREE PostgreSQL database?๐
๐ฆ Check Aiven’s FREE plans! ๐ฆ
Convert an array to a JSON array with the array_to_json
function
You can convert an array to a JSON array with the array_to_json
(array_to_jsonb
for JSONB) function
select array_to_json(
ARRAY['๐', '๐ถ๏ธ', '๐']);
Result
array_to_json
-----------------
["๐","๐ถ๏ธ","๐"]
(1 row)
Review all the JSON PostgreSQL use-cases listed in the main page