0

I have this huge string that's a key value of an object of mine (I didn't make this, it was generated by a bot).

I'm trying to grab the text out on the front end and display it. So in the case of: "text : hi" I'd want to grab 'hi' out and display it. I know I can search for the text using substrings, but the only thing I know if that 'text' will be there, but I want the data after it and I don't know what that data will be every time.

"{"event": "user", "timestamp": 1583019471.5611057, "text": "Alex", "parse_data": {"intent": {"name": "utter_interview", "confidence": 0.6946980357170105}, "entities": [], "intent_ranking": [{"name": "utter_interview", "confidence": 0.6946980357170105}, {"name": "utter_greet", "confidence": 0.18765409290790558}, {"name": "utter_closeout", "confidence": 0.11764788627624512}], "text": "Alex"}, "input_channel": "rest", "message_id": "0375d021d0fd4a8eb2ff8f519c72d8d6", "metadata": {}}"

How can I do this?

Pichi Wuana
  • 732
  • 2
  • 9
  • 35
monsterpiece
  • 739
  • 2
  • 12
  • 34

1 Answers1

1

I think you can go for

const data = JSON.parse(string);
const text = data.text

If the string that you pasted is the value in the parsed JSON, you need to further parse it which is the above step.

However, if you don't want to parse it, you can use regex and match the text key.

vam
  • 492
  • 7
  • 17