PostgreSQL - how to generate an array containing column name and column data...? I'd like to create a dictionary - an array - from a simple query, to include column names in output.

IE, I'd like to turn this:

SELECT id, last, first FROM names;

  id | last     | first        
-----+----------+-------------------------
001  | Smith    | John


into:

{ "id": "001","last": "Smith", "first": "John" }


Yes, bonus points for the quotes and colons! Ha!

We do have this very interesting catalog function, which will return all column names into an array.

SELECT array_agg(column_name::TEXT) 
FROM information_schema.columns 
WHERE table_name = 'people';


How to aggregate (couldn't help myself) that into a regular query?
The first one can be done using a JSON function

select to_jsonb(n)
from names n;


I have no idea what you want to achieve with the second query.