How to extract information from angular output

Viewed 44

If I log the full data from an Angular client I get

object { type: "message", target: {_}, errorCode: undefiend, errorMessage: undefined, data: "{\"data\":[\"124",\"611\"]}", lastEventId: ""}

I want to grab the {\"data\":[\"124",\"611\"]} part to send it as json to a client. Using JSON.parse(data.data) though gives me

data: "{\"data\":[\"124",\"611\"]}", lastEventId: ""}

Is it possible to just grab the "{\"data\":[\"124",\"611\"]}" since otherwise the client has problems with the deserialization.

1 Answers

Let's say you have your initial string in myobject_string. Then, you extract the JSON to a Javascript object with: const myobject = JSON.parse(myobject_string).

Then, the data you are looking for is in myobject.data.

Look here for more example code on JSON.parse.

Related