JSFiddle - React, Tailwind, and code Playground
by kneidels
JavaScript
const jsonPayload = `{
"message": {
"id": "msg_1Wvv7fRrts4u9TO4BVDieW",
"type": "UserMessage",
"origin": "web",
"location": null,
"text": "asdasd",
"custom": {},
"content": [
{ "children": ["asdasd"], "type": "text" }
],
"attachment": null,
"createdAt": 1735130775688,
"conversationId": "1734948015815",
"editedAt": null,
"referencedMessageId": null,
"senderId": "moshe",
"readBy": []
},
"timestamp": 1735130775688,
"body": "asdasd",
"sender": {
"id": "moshe",
"name": "Moshe Tapnack",
"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
}
}`;
const parsedPayload = JSON.parse(jsonPayload); // Parse JSON string into object
const textValue = parsedPayload.message.text; // Access the 'text' key
console.log(textValue); // Output: "asdasd"