Recipe for converting postgres table into json