Add toJson method to controller