I am retrieving a list of files that have been uploaded from a backend endpoint, and it comes back in this format:
[
{
"filename": "setup.cfg",
"id": 1,
"path": C:\\back-end\\uploads\\setup.cfg",
"uploaded_at": "Fri, 01 Jun 2018 09:25:19 -0000"
},
{
"filename": "57760713_1467275948.jpg",
"id": 2,
"path": "C:\\back-end\\uploads\\57760713_1467275948.jpg",
"uploaded_at": "Mon, 04 Jun 2018 09:09:59 -0000"
},
.
.
.
]
Along with this data, I have a TypeScript interface designed like so:
export interface UploadModel {
id: number;
name: string;
path: string;
uploadedAt: Date;
}
The issue lies in the naming conventions used; the returned data follows snake_case as uploaded_at
while my interface uses camelCase as uploadedAt
.
I'm looking to fetch this information from the backend using the following code snippet:
getUploads(): Observable<UploadModel[]> {
this.http.get(UPLOADS_ENDPOINT)
.map((response: Response) => {
// Need to parse the JSON response here and return an array of UploadModels
});
}
Any tips on how to effectively map these two representations without manually iterating through the array of JSON objects?