Refactored code to convert model to json