When working with Angular2 (TypeScript), I encountered a class that has the following constructor:
export class DataModel {
constructor(public date_of_visit: string,
public gender: boolean,
public year_of_birth: number,
public height: number,
public weight: number){}
}
In addition, there is a JSON object available:
json = {"date_of_visit": "23/09/2016", "gender": 1, "year_of_birth": 1975, "height":185, "weight": 85}
My question: How can we easily create an instance of DataModel using the JSON data as input? Can we achieve this with something like new DataModel(**json)
?