Examining this JSON structure:
{
"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 ..."
}
}
// other entries...
]
}
How do I deconstruct this object to extract these specific components: Person, Notes.Note[].
This is my attempted solution, which unfortunately does not yield the desired outcome:
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 => {
}
);
Referencing TypeScript's documentation for guidance on destructuring: TypeScript Destructuring Documenation