De-obfuscating the aggregate json code

Seperating out the json_aggregate function into two to deal with the
aggregate and aggregate item pages separately.
Leads to code repetition, but much easier to read.
Also threw some comments in for the sorry lot who have to pick up where
we left off.
Merge pull request #114 from dannybutler/master

De-obfuscating the aggregate json code