Use helpers to generate JSON.

This moves the logic for generating the JSON response out of the model
and into helpers.