Q:

Angular - parse json string created by json dumps

I couldn't  find a helpful solution.
I work in python 3.6 (django rest-framwork) server side and angular 5 client side.
At the server:
class TypesView(APIView):
    def get(self,request):
        a = ['Cat','Dog']
        j = json.dumps(a)
        return Response(data=j, status=status.HTTP_200_OK)

I am trying to parse this at the client:
  public getAnimalRaces(): Observable<string[]>{
     const path = environment.apiEndpoint + "animals/races/"
    return this._http_client.get<string[]>(path)
  }

but I keep getting:
Error trying to diff '["Cat", "Dog"]'. Only arrays and iterables are allowed
This is what Being returned to the client:
"[\"Cat\", \"Dog\"]"

any ideas?

A:

You are trying to iterate on a string.
You need to parse the response as JSON which will turn the response into an array which you can then use with *ngFor in the template for example.
this._http_client.get<string[]>(path)
  .map((res) => JSON.parse(res));

