I am trying to convert API response (json string array) to typescript object but not able to achieve . I tried to add map function but not able to use it properly.
Sample API response is ["Paris","London","New York"]
my City class is like this
export class City { Name:string;
isAvailable: boolean;
}
My function
public getCities(queryId: string) : Observable<City[]> {
const url = apiUrl;
const response = this.http.get<string[]>(url)
.pipe(catchError(this.handleError));
//how can i add map method here to convert String to City object?
return response;
}
I expect output like
[
{Name:"Paris",isAvailable:true},
{Name:"London",isAvailable:true},
{Name:"New York",isAvailable:true}
]
.pipe(map(response => response.map(name => { Name: name, isAvailable: true } as City)))