Convert character varying(255)[] to JSONB I currently have array of strings character varying(255)[] and want to convert it to a JSONB object. When I try to cast it directly, it results in an error, despite it being a valid JSON, is there a nice way to convert it?: 

ERROR:  cannot cast type character varying[] to jsonb
You can not convert the array of strings to the single JSON object (directly at least). If you need to convert it to the array of JSONs use

select yourvalue::jsonb[];


If you need to convert it to the JSON array use

select jsonb_agg(unnest::jsonb) from unnest(yourvalue);


or

select to_jsonb(yourvalue::jsonb[]);


where yourvalue::jsonb[] ensures that all values in the array is really valid JSON and to_jsonb(...) converts it to the JSONB array.

Example:

with t(x) as (values(array['["a","b","c"]','{"d":"e"}','1']))
select to_jsonb(x::jsonb[]) from t;


Output:

[["a", "b", "c"], {"d": "e"}, 1]