converting postgres table to json