Group Rails query into arrays by attribute
If you're actually dealing with JSON:
people.group_by{|p| p['age'] }
If you're dealing with ActiveRecord models:
People.group('id, age')
Here there's additional documentation on grouping with ActiveRecord.