I'm trying to create a view with aggregated data displayed as a json object:
thing_named_not_unique | emergency_code
------------------------+----------------
foo | 1
foo | 2
foo | 1
bar | 1
bar | 2
To have the results be
thing_named_not_unique | emergency_code_counts
------------------------+----------------
foo | {'1': 2, '2': 1}
bar | {'1': 1, '2': 1}
I'm pretty new to Postgres JSON functions and can't figure out how to build an aggregate for this.