Penso che dovrebbe essere relativamente facile da fare con functions-json
:
select
json_agg(to_json(d))
from (
select
e.humd as "relativeHumidity",
e.wind as "windSpeed",
l.address,
json_build_object(
'coordinates',
json_build_array(l.log, l.lat)
) as location
from environment as e
inner join placement as p on
p.placem_id = e.placem_id
inner join location as l on
l.loc_id = p.loc_id
) as d