I have written a method in an Angular 2 app that creates and returns an Observable of a class, after making a server call that returns JSON. However, the JSON is poorly formatted, so I need a quick-fix to edit the returned JSON before sending it on to the .json()
method, which currently throws an error due to the poorly-formatted JSON.
Specifically, I need to find an errant comma in the JSON that appears after the closing bracket of an array, and remove it.
My Question
What exactly should that Observable.map function look like? How do I find and manipulate the actual JSON string, and then send it along? I'm new to all of this, so details would be appreciated.
getList(): Observable<Thing[]> {
let response = this.http.get('/api/get-things');
let fixed = response.map(____WHAT GOES HERE?_____);
return fixed.map((r: Response) =>r.json as Thing[]);
}