I have a complex database with keys and values stored in different tables. It is useful for me to aggregate them when pulling out the values for the application:
Can't you use json_agg?
json_agg
select json_agg(txt) from test; json_agg -------------------------------------- ["one", "two", "three", "four five"]