Reputation: 15129
I have an array of strings, like this:
SELECT ARRAY['[email protected]', '[email protected]', '[email protected]'];
How do I convert (map?) it into a jsonb array of jsonb objects like this?:
SELECT [{"email": "[email protected]"}, {"email": "[email protected]"}, {"email": "[email protected]"}]::jsonb;
Upvotes: 3
Views: 272
Reputation: 23756
SELECT
jsonb_agg(jsonb_build_object('email', elems))
FROM (
SELECT ARRAY['[email protected]', '[email protected]', '[email protected]'] AS a
) s,
unnest(a) AS elems
unnest()
jsonb_object_build()
to create the key/value structure your are expectingjsonb_agg()
Upvotes: 4