Only works with queries that respond to .to_sql (not .find).
Uses PostgreSQL json aggregate function to wrap Active Record queries to directly output as json.