The JSON encoding should be done by the view where it belongs to