If we receive the following data from the backend:
{
idPerson:string,
name: string
}
Let's say I have a TypeScript class like this:
class Option {
id: string;
text: string;
}
Now, suppose the backend sends us this data:
"[{idperson: "1", name: "foo"}, {idperson:"2", name:"bar"}]"
When I make an Angular HTTP request and get the response, I'm parsing it like this:
let options: any[] = [];
options = JSON.parse(response);
So far, the output looks like:
[{idperson: "1", name: "foo"}, {idperson:"2", name:"bar"}]
But what I really want is to map the keys from backend to frontend keys to achieve this format:
[{id: "1", text: "foo"}, {id:"2", text:"bar"}]
Is there a way for me to do this key mapping?