# "typeError: Cannot Read Properties of undefined (reading '0')"

**URL:** https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536
**Category:** General
**Tags:** database, function-node
**Created:** [4 October 2022 09:56 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536 "2022-10-04T09:56:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Drewdrops](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@Drewdrops](https://discourse.nodered.org/u/Drewdrops)
#### Post date: [4 October 2022 09:56 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/1 "2022-10-04T09:56:42Z")

</div>

Having issues with my node RED Code

trying pull information from Watson but getting an error in my function node

CODE:  
msg.payload = {

```
    chatId : msg.chatId,
    type : "message",
    content : msg.payload.output.text[0]

```

};  
return msg;

ERROR:

"TypeError: Cannot read properties of undefined (reading '0')"

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [4 October 2022 10:08 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/2 "2022-10-04T10:08:18Z")

</div>

Hello @Drewdrops, welcome to the forum.

Can you put a debug node to show the data coming from Watson?  
Set it to display the complete msg, so we can see the values of msg.chatId and msg.payload.

---

<div class="post-metadata">

### Author: ![Drewdrops](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@Drewdrops](https://discourse.nodered.org/u/Drewdrops)
#### Post date: [4 October 2022 10:14 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/3 "2022-10-04T10:14:02Z")

</div>

I have attached a debug to the Watson node. Getting this

object

output: object

intents: array[1]

0: object

intent: "Howdy"

confidence: 1

skill: "main skill"

entities: array[0]

generic: array[1]

0: object

response\_type: "text"

text: "Howdy"

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 October 2022 10:16 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/4 "2022-10-04T10:16:40Z")

</div>

please use the "copy value" button when copying a msg or its payload  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ace45f1bcad767c4fdf557f7e1ca6a0ea7ecc6cb.png)

Also, use the forum `</>` code button BEFORE pasting the copied value.

What you have pasted is unusable.

---

<div class="post-metadata">

### Author: ![Drewdrops](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@Drewdrops](https://discourse.nodered.org/u/Drewdrops)
#### Post date: [4 October 2022 10:24 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/5 "2022-10-04T10:24:55Z")

</div>

```auto
{"output":{"intents":[{"intent":"Howdy","confidence":1,"skill":"main skill"}],"entities":[],"generic":[{"response_type":"text","text":"Howdy"}]},"user_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760","context":{"global":{"system":{"session_start_time":"2022-10-04T09:55:23.307Z","turn_count":1,"user_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760","state":"eyJpZCI6IjM1M2ZhZjIwLWNmODMtNGYzNy04MDA3LTQ2ZmU0MDhlN2FhZSIsInNraWxscyI6W3siY29uZmlnIjp7ImFjdGlvbnMiOmZhbHNlLCJ3b3Jrc3BhY2VfaWQiOiIwYWYyODBhZi0yZDBlLTQ3OTYtYmE2NS1iYWRkNmZkOWRkNzciLCJza2lsbF9yZWZlcmVuY2VfaWQiOm51bGx9LCJkaXNhYmxlZCI6ZmFsc2UsImxhbmd1YWdlIjoiZW4iLCJza2lsbF90eXBlIjoiZGlhbG9nIiwic2tpbGxfcmVmZXJlbmNlIjoibWFpbiBza2lsbCIsInNraWxsX3NuYXBzaG90X2lkIjpudWxsLCJza2lsbF9zbmFwc2hvdF9uYW1lIjpudWxsLCJ3b3JrZXJfZGVmaW5pdGlvbl9pZCI6IjBhZjI4MGFmLTJkMGUtNDc5Ni1iYTY1LWJhZGQ2ZmQ5ZGQ3NyJ9LHsiY29uZmlnIjp7Im1lc3NhZ2UiOm51bGwsInZlcnNpb24iOiIyMDE4LTEyLTAzIiwiaGlnaGxpZ2h0IjpudWxsLCJpbnN0YW5jZV9pZCI6bnVsbCwiY29sbGVjdGlvbl9pZCI6bnVsbCwiZGlzY292ZXJ5X3VybCI6bnVsbCwiZXJyb3JfbWVzc2FnZSI6bnVsbCwiZW52aXJvbm1lbnRfaWQiOm51bGwsInJlc3VsdHNfcGVyX3BhZ2UiOm51bGwsIm1heF90b3RhbF9yZXN1bHRzIjpudWxsLCJub19yZXN1bHRfbWVzc2FnZSI6bnVsbCwicGFnaW5hdGlvbl9lbmFibGVkIjpmYWxzZSwic2NoZW1hX21hcHBpbmdfdXJsIjpudWxsLCJtYXhfcHJpbWFyeV9yZXN1bHRzIjpudWxsLCJzY2hlbWFfbWFwcGluZ19ib2R5IjpudWxsLCJiYXNpY19hdXRoZW50aWNhdGlvbiI6bnVsbCwic2NoZW1h..."},"session_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760"},"skills":{"main skill":{"system":{}}}},"session_id":"4f5c2d04-d992-4dd4-8eb2-f8a217f32760"}

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [4 October 2022 10:30 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/6 "2022-10-04T10:30:13Z")

</div>

> [@Drewdrops](#):
>
> `content : msg.payload.output.text[0]`

This is not a valid path (given your data)

The safest way to determine the path to an item is to use the built in tools - in this case, "copy path"  
 ![chrome_hspz14YGHn](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7e50f193800b9f84e3bcbc275ef874960b1274f.gif)

That results in : `msg.payload.output.generic[0].text`

---

<div class="post-metadata">

### Author: ![Drewdrops](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@Drewdrops](https://discourse.nodered.org/u/Drewdrops)
#### Post date: [4 October 2022 10:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/7 "2022-10-04T10:34:22Z")

</div>

Thank you so much

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 October 2022 10:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-reading-0/68536/8 "2022-10-18T10:34:45Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
