Refactored out the ReturnAsJson method to its own helper