# Get data out of object

**URL:** <https://discourse.nodered.org/t/get-data-out-of-object/1657>\
**Category:** General\
**Created:** [18 July 2018 08:38 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657 "2018-07-18T08:38:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickB](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@NickB](https://discourse.nodered.org/u/NickB)\
**Post date:** [18 July 2018 08:38 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/1 "2018-07-18T08:38:38Z")

</div>

This should be quite easy, but I don't see what's going wrong.

I receive an object. In this object you have the element 'Label' and 'CurrState'.

When labels has the value Sensor and Currstate is True, I just want to pass a '1' to trigger the next action.

I thought I could 'acces' the element label like Payload.Label, but that does not seems to be the case.

Here are some sreenshots;

1. What my object looks like:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3953c746933e0b48fe0915bed2301da1e7bc235a.png)

2. My actual function, just looking if sensor is in it. If it is I would expect a 1 at the output...  
This needs to be expand by also verifying the CurrState  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/56a9ee716a1c60a5853a187092259f0201ac8a57.png)

3. What my function gives as output....  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3461b9899532c10369667a53ee2ff9f2ee7933cd.png)

> [{"id":"ae21c3f.f339a4","type":"zwave-in","z":"154afdd3.672442","name":"MyStick","controller":"49a56b32.da7d44","x":157,"y":117,"wires":[["443ab2c6.2e546c","6951552d.f93a1c"]]},{"id":"6951552d.f93a1c","type":"debug","z":"154afdd3.672442","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":562,"y":115,"wires":},{"id":"443ab2c6.2e546c","type":"function","z":"154afdd3.672442","name":"test","func":"var x = payload.label;\n\nif (x== "Sensor") {\n var msg\_o = {payload : 1}\n} else {\n var msg\_o = {payload : 0}\n}\nreturn msg\_o;\n\n\n","outputs":1,"noerr":0,"x":361,"y":170,"wires":[["64a6f96c.218658"]]},{"id":"64a6f96c.218658","type":"debug","z":"154afdd3.672442","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"Sensor","x":554,"y":178,"wires":},{"id":"49a56b32.da7d44","type":"zwave-controller","z":"","port":"/dev/ttyACM0","driverattempts":"3","pollinterval":"10000","allowunreadyupdates":false,"networkkey":"","logging":true}] Blockquote

Thx for having a look

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 July 2018 08:52 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/2 "2018-07-18T08:52:58Z")

</div>

You realise that there is a rather nice icon on the RHS of the line you highlight that lets you copy the path to the element?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 July 2018 08:53 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/3 "2018-07-18T08:53:54Z")

</div>

> [@NickB](#):
>
> Payload.Label

Nope. It is `msg.payload.label`

Also, case is important in JavaScript so `Payload` wouldn't work anyway.

---

<div class="post-metadata">

**Author:** ![NickB](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@NickB](https://discourse.nodered.org/u/NickB)\
**Post date:** [18 July 2018 09:21 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/4 "2018-07-18T09:21:01Z")

</div>

Hi,  
thanks.

I did copy it, because first I used it like you mentioned.  
But the result was not ok either.

Know I don't have the fault anymore, but my payload is 'undifined'?  
I removed the ELSE, because othersiwe I get the 'undifined' after every message, now I get the undifened after the 'sensor' message.

So it is well reading msg.payload.label, but why don't I receive a nice '1'?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/aa9d65b5924e1a4432558bf48d5d5ed0ec3c0605.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [18 July 2018 09:47 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/5 "2018-07-18T09:47:58Z")

</div>

That’s a different error, this time caused by your output variable which you should declare as an object.

so try adding this line at the start of your function

var msg\_o = {};

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 July 2018 09:49 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/6 "2018-07-18T09:49:06Z")

</div>

@NickB the highlighted debug messages are showing `msg.Sensor` - which is not defined in the message your Function node is returning.

---

<div class="post-metadata">

**Author:** ![NickB](https://avatars.discourse-cdn.com/v4/letter/n/f08c70/32.png) [@NickB](https://discourse.nodered.org/u/NickB)\
**Post date:** [18 July 2018 11:41 UTC](https://discourse.nodered.org/t/get-data-out-of-object/1657/7 "2018-07-18T11:41:38Z")

</div>

Thanks to all. I've got it

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2c3c07f6ed391a4bde103a0094246b01ab57704e.png)

@knolleary , I totally went wrong on msg.sensor. I just wanted to display a name on my debug node calling sensor. Offcourse the whole meaning is different like that.
