Sukai @Abelisto dikomentari
, gunakan json_build_object()
(atau jsonb_build_object()
) untuk melampirkan kunci ke nilai Anda.
Dan json_agg(t)
(atau jsonb_agg(t)
) bukannya array_to_json(array_agg(t))
:
SELECT json_build_object('Locations', json_agg(t))
FROM (
SELECT DISTINCT ON (city, state)
latitudes, longitudes, city, state
FROM zips
WHERE city ILIKE 'ORL%'
ORDER by city, state, ziptype DESC
LIMIT 10
) t;