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.

2
  • 1
    It's a type string, so parse it to JSON object then .data Commented Jan 16, 2019 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. Commented Jan 16, 2019 at 13:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.