I have a json result, which is a collection of objects. I need to send them to a collection of custom objects that have different property names than the json result. Also, not all properties of the result are necessary in this case.
Json
[{"empID":"12345", "formattedName":"Simpson, Homer"}, {"empID":"24680", "formattedName":"Simpson, Marge"}, {"empID":"36912", "formattedName":"Simpson, Bart"}, {"empID":"13579", "formattedName":"Simpson, Lisa"}, {"empID":"13579", "formattedName":"Simpson, Lisa"}]
My custom ojbect
export class multiSelect { constructor( public id: string, public name: string ) { } }
Service
reportsTo(): Observable<multiSelect> { return this._http.get('getCollection') .map((response: Response) => response.json()) .map(({empID, formattedName}) => new multiSelect(empID, formattedName)) .catch(this.handleError); }
I would like my service to return this
[{"id":"12345", "name":"Simpson, Homer"}, {"id":"24680", "name":"Simpson, Marge"}, {"id":"36912", "name":"Simpson, Bart"}, {"id":"13579", "name":"Simpson, Lisa"}, {"id":"13579", "name":"Simpson, Lisa"}]
Any help would be greatly appreciated. Thanks.