mongotop mongotop - 3 months ago 6
JSON Question

Convert LIST of JSONs to a list of strings using postgresql

I have this of

JSON
object :

[{"name":"steven","dob":"1979-02-10"},{"name":"Chris","dob":"1981-01-05"},]


I want to convert the object above to a
LIST
of the names from the
JSON
objects like :

["steven", "Chris"]


Is there's a postgresql function to do that?

I checked the documentation HERE and could not find the right function

Answer

Try this:

SELECT json_agg(value->>'name') FROM json_array_elements('[{"name":"steven","dob":"1979-02-10"},{"name":"Chris","dob":"1981-01-05"}]');
Comments