json_agg
devuelve nulo de un conjunto vacío:
select json_agg(t.*) is null
from (select 'test' as mycol where 1 = 2) t ;
?column?
----------
t
Si desea una matriz json vacía coalesce
es:
select coalesce(json_agg(t.*), '[]'::json)
from (select 'test' as mycol where 1 = 2) t ;
coalesce
----------
[]