I have the following JSON, and I have tried various formats of reading a specific key without success.
This is a web push notification coming from TalkJS, below.
As well as what it looks like in the console.
I am looking for the TEXT
key value, which in this case is hello
I have tried payload.text
and payload.message.text
but they both come out undefined.
"{"message":{"id":"msg_303fpzqsELNIYT6udk6A52","type":"UserMessage","origin":"web","location":null,"text":"hello","custom":{},"content":[{"children":["hello"],"type":"text"}],"attachment":null,"createdAt":1735132581656,"conversationId":"1734948015815","editedAt":null,"referencedMessageId":null,"senderId":"user","readBy":[]},"timestamp":1735132581656,"body":"hello","sender":{"id":"user","name":"User Tap","custom":{},"email":["[email protected]"],"role":"thadmin","locale":"en-EN","photoUrl":"https://talkjs.com/images/avatar-4.jpg","createdAt":1730821509211,"welcomeMessage":"Hi!","phone":null,"availabilityText":null,"pushTokens":{}},"conversation":{"id":"1734948015815","custom":{"status":"open","type":"personal"},"subject":"test55","photoUrl":null,"participants":[],"createdAt":1734948017190,"topicId":null,"welcomeMessages":null}}"
2
Can you Try This One
const talkjsData = payload.data.talkjs;
const parsedTalkjsData = JSON.parse(talkjsData);
const textValue = parsedTalkjsData.text;
console.log(textValue);
Raj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.