Given this JSON object:
{
"Person": {
"UID": 78,
"Name": "Brampage",
"Surname": "Foo"
},
"Notes": [
{
"UID": 78,
"DateTime": "2017-03-15T15:43:04.4072317",
"Person": {
"Name": "Brampage",
"Surname": "Foo"
},
**"Note":** {
"Title": "Lorem Ipsum...",
"Content": "Blaat blaat blaat blaat ..."
}
},
{
"UID": 78,
"DateTime": "2017-03-15T15:43:04.4072317",
"Person": {
"Name": "Brampage",
"Surname": "Foo"
},
"Note": {
"Title": "Lorem Ipsum...",
"Content": "Blaat blaat blaat blaat ..."
}
}
// etc.
]
}
How should I destructure this object so that I will be left over with this data: Person, Notes.Note[].
This is what I have tried to accomplish the above, however it does not work:
this.http.get(url)
.map(res => {
const jsonObject = res.json();
// Destructuring
const { Person} = jsonObject;
const [{ Note }] = jsonObject.Notes;
return {
person: Person,
note:[
Note
]
}
})
.subscribe(
usefullInformation => {
console.log(usefullInformation);
},
error => {
}
);
This is TypeScript's documentation on how to destructure: TypeScript Destructuring Documenation