mongotop mongotop - 1 year ago 85
JSON Question

Convert LIST of JSONs to a list of strings using postgresql

I have this of

object :


I want to convert the object above to a
of the names from the
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 Source

Try this:

SELECT json_agg(value->>'name') FROM json_array_elements('[{"name":"steven","dob":"1979-02-10"},{"name":"Chris","dob":"1981-01-05"}]');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download