Still not a reason to not leverage the database. Use something like Postgres' ARRAY_AGG; reduces the duplicates, faster and better than rolling your own JOINs in your app.
I wish postgres had FOR JSON (https://learn.microsoft.com/en-us/sql/relational-databases/j...)