# Need help, funtion node, extracting payload

**URL:** <https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128>\
**Category:** General\
**Created:** [19 February 2019 04:06 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128 "2019-02-19T04:06:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asbjoern](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Asbjoern](https://discourse.nodered.org/u/Asbjoern)\
**Post date:** [19 February 2019 04:06 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128/1 "2019-02-19T04:06:23Z")

</div>

Hi  
I'm New to Node-Red, but have spent several days on youtube and google trying to figure this out. I would appreciate if you could help me over this bump in the road.

What I'm trying to do, is to get information out of SignalK JSON delta messages imported through websocket, and display it on the Node-Red Dashboard.

 ![source%20JSON](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a5b068a5bd50e2dc196cc31bdd5c07e7ef754b8b.jpeg)

I'm New to JavaScript, and I'm pretty sure this is where my problem is:

```auto
if (msg.updates[0].source.pgn === "129025") {
    msg.payload = msg.updates[0].values[0].value.longitude;
      return [msg, null];
}
if (msg.updates[0].source.pgn === "129025") {
    msg.payload = msg.updates[0].values[1].value.latitude;
      return [null, msg];
}

```

The websocket spams Node-Red With several JSON messages every second, and most of them are formatted the same way, I therefore need to check the PGN number of a Message to make sure it is the Message With the right data before extracting the sensor Readings.

For some reason my JavaScript doesn't work. Where the numbers should be on the Dashboard it's just blank. Debug gives me this:

19‎.‎02‎.‎2019‎ ‎05‎.‎03‎.‎20[node: navigation.position](http://10.0.1.105:1880/debug/view/view.html#)function : (error)

"TypeError: Cannot read property '0' of undefined"

Please help 🙂

---

<div class="post-metadata">

**Author:** ![Asbjoern](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Asbjoern](https://discourse.nodered.org/u/Asbjoern)\
**Post date:** [19 February 2019 04:09 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128/2 "2019-02-19T04:09:55Z")

</div>

I was only allowed on image per post, here is the flow if that helps:

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6c3642a21a6428d75f9915f046e73ee38b4b626c.jpeg)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 February 2019 06:36 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128/3 "2019-02-19T06:36:38Z")

</div>

> [@Asbjoern](#):
>
> `msg.updates[0].source.pgn === "129025"`

You are comparing text to a number.

`msg.updates[0].source.pgn === 129025`  
Also, "_and most of them are formatted the same way_" - you will need to capture exceptions

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 February 2019 08:46 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128/4 "2019-02-19T08:46:00Z")

</div>

> [@Asbjoern](#):
>
> TypeError: Cannot read property '0' of undefined"

That says that you have tried to use `[0]` on an object that does not exist. That in turn means that `msg.updates` does not exist. So the message coming in does not have a property `msg.updates`, so the message coming in is not the one you show in your post.  
If the reason is that some messages do not have this, and you just want to ignore these then you can replace your test with something like

```auto
if (msg.updates && msg.updates[0].source.pgn === 129025) {

```

so it tests for msg.updates present before looking for the data.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 February 2019 11:39 UTC](https://discourse.nodered.org/t/need-help-funtion-node-extracting-payload/8128/5 "2019-02-19T11:39:26Z")

</div>

Also if the first  
`if (msg.updates[0].source.pgn === "129025") {`  
is true, you will never get to the second  
`if (msg.updates[0].source.pgn === "129025") {`  
since the first if does a return and the two if conditions are exactly the same.
