Added function to created json from model, extended json encoder to handle models