2

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.

ruedi
  • 5,365
  • 15
  • 52
  • 88
  • 1
    It's a type string, so parse it to JSON object then `.data` – penleychan Jan 16 '19 at 12:58
  • Should I do this mydata => Json.parse(data) and can then get the string I want by mydata.data. Is that what you mean? Sorry, this is absolutely not my terrain. – ruedi Jan 16 '19 at 13:02

1 Answers1

3

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.

Qortex
  • 7,087
  • 3
  • 42
  • 59