# How to select an Object in payload

**URL:** <https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440>\
**Category:** General\
**Created:** [24 April 2020 19:47 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440 "2020-04-24T19:47:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [24 April 2020 19:47 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/1 "2020-04-24T19:47:46Z")

</div>

Dear friends,  
I faced a very simple problem that confused me !  
I have such a payload :

```auto
4/25/2020, 12:07:15 AMnode: 6c705480.72452c
msg.payload : Object
object
number: ""12817""
date: ""20/04/24"
time: "22:10:00+18"↵"

```

and I want to put an If statement in function node.  
I try both of these ,but none worked !

```auto
if(msg.payload.number == "12817")
{
    return msg;
}

```

and also :

```auto
if(msg.payload.number === "12817")
{
    return msg;
}

```

So whats the problem ?

---

<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:** [24 April 2020 19:53 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/2 "2020-04-24T19:53:03Z")

</div>

Send it to the debug window, expand the msg, click the item of interest then click the middle button to copy the variables path.

Also, read [this](https://nodered.org/docs/user-guide/messages) - spend 10 minutes reading this. Well worth it.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [24 April 2020 19:57 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/3 "2020-04-24T19:57:14Z")

</div>

Your object values are JSON strings for some reason. you would have to do a JSON.parse() for each key value pair.  
That’s why you see the double "" on each side of the values.

---

<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:** [24 April 2020 20:01 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/4 "2020-04-24T20:01:07Z")

</div>

Where does that data come from? You have probably done something not the best way in getting that data in the first place. Such as not converting a JSON string to an object rather than trying to extract data manually from a JSON string.

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [24 April 2020 20:02 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/5 "2020-04-24T20:02:19Z")

</div>

Exactly ! ❤  
I try :

```auto
if(JSON.parse(msg.payload.number) == "12817")

```

and it works ....  
Thanks

---

<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:** [24 April 2020 20:03 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/6 "2020-04-24T20:03:26Z")

</div>

yeah, but as @Colin states, its not normal to have to do that.

show your flow & we'll see if we can correct it.

---

<div class="post-metadata">

**Author:** ![tarahi](https://avatars.discourse-cdn.com/v4/letter/t/9de053/32.png) [@tarahi](https://discourse.nodered.org/u/tarahi)\
**Post date:** [24 April 2020 20:07 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/7 "2020-04-24T20:07:37Z")

</div>

Thanks for the point .  
It is a part of long flow ,  
I try to solve that problem else ,  
I learn 2 simple but important points , Thanks All ..

---

<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:** [8 May 2020 20:07 UTC](https://discourse.nodered.org/t/how-to-select-an-object-in-payload/25440/8 "2020-05-08T20:07:37Z")

</div>

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