After receiving JSON data from a REST web service, I am exploring ways to convert it into an array of objects.
{
"John": "Buttler"
"Hugh": "Martin"
.
.
.
}
I envision converting it into the following object structure. Essentially, I anticipate an array of Person objects where John and Hugh represent first names, and Buttler and Martin denote last names.
export class Person{
firstName: string;
lastName: string;
}
If the JSON were structured as:
[
{
"firstName": "John",
"lastName": "Buttler"
},
{
"firstName": "Hugh"
"lastName": "Martin"
}
]
Below is a snippet of the Angular Service Code:
findAllPersons(): Observable<Person[]> {
return this.httpClient.get<Person[]>('url');
}