Is there a way to create an enum from a JSON REST API?
Here is the code I currently have in my service.ts file:
getDataFromJson(): Observable<any> {
return this.httpClient.get<any>(`../../../assets/gender.json`)
.pipe(map(data => {
return data;
}));
}
However, the data is returned in this format:
[
{
"name": "Female",
},
{
"name": "Male",
}
]
Using this code:
getGenders: any = {}
getGender() {
this.options.getDataFromJson().subscribe(data => {
this.getGenders = data;
})
}
Instead of the current format, I would like the data to be returned as an enum type and placed in my gender.ts file like this:
export enum Gender {
Male = 'Male',
Female = 'Female',
}
Any suggestions on how to achieve this are greatly appreciated.