# Retrieve values from payload object

**URL:** <https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764>\
**Category:** General\
**Created:** [21 April 2023 01:37 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764 "2023-04-21T01:37:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [21 April 2023 01:37 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/1 "2023-04-21T01:37:36Z")

</div>

Hi all,

New to node-red here, and looking to store some IoT data coming from TTN into a postgres database.  
I am having a hard time formatting the data.  
Here is the payload I receive

```auto
4/21/2023, 1:19:29 AM[node: msg.payload](http://xx.xxx.xx.xxx:1880/#)v3/xxxxx@sxxxx/devices/eui-x/up : msg.payload : Object

object

Bat: 3.354

TempC_DS18B20: "0.0"

conduct_SOIL: 89

temp_SOIL: "21.04"

water_SOIL: "22.02"`

```

Here is the function I use to format the data :

```auto
msg.payload = {
        timestamp_data: new Date(),
        device_battery: parseFloat(msg.payload.Bat),
        soil_conductivity: parseInt(msg.payload.conduct_SOIL),
        soil_temperature: parseFloat(msg.payload.temp_SOIL),
        soil_humidity: parseFloat(msg.payload.water_SOIL)
        
        
        
    };
return msg;

```

But when I do this here is what I receive :

```auto
4/21/2023, 1:33:24 AM[node: msg.payload](http://xx.xxx.xx.xxx:1880/#)v3/xxxxx@sowit/devices/eui-x/up : msg.payload : Object

{ timestamp_data: "2023-04-21T01:33:23.953Z", device_battery: NaN, soil_conductivity: NaN, soil_temperature: NaN, soil_humidity: NaN }

```

I don't understand why I get NaN instead of the values, happy to get your insights.

Thanks,  
HB

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 April 2023 05:50 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/2 "2023-04-21T05:50:21Z")

</div>

Can you put a debug node on and let us see the output of the data that you are getting returned back from the API call ?

That would make it easier to understand what us happening

Craig

---

<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:** [21 April 2023 09:03 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/3 "2023-04-21T09:03:52Z")

</div>

MODERATOR NOTE: I have edited your post and removed the IP address you included as your NR site is accessible from the internet.

THIS IS DANGEROUS AND YOU OPEN YOURSELF TO BEING HACKED.

I would recommend you take steps to secure your site before you do anything else!

---

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [21 April 2023 09:18 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/4 "2023-04-21T09:18:51Z")

</div>

Hi @zenofmud thank you for the initiative, point taken.

best regards,  
HB

---

<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:** [21 April 2023 10:03 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/5 "2023-04-21T10:03:32Z")

</div>

Add a `debug` node to the output of all the `mqtt-in` nodes to show the data each `function` node is getting. Then copy/paste the debug's msg.payload in a response.

---

<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:** [21 April 2023 10:49 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/7 "2023-04-21T10:49:05Z")

</div>

Is that the debug output of the `mqtt-in` node that feeds the `function` node with the issue?

---

<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:** [21 April 2023 11:02 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/9 "2023-04-21T11:02:20Z")

</div>

You are trying to access msg.payload.Bat but the value for "Bat" is msg.payload.uplink\_message.decoded\_payload.Bat.

I discovered this using the "Copy path" button on the debug panel.

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/99094dcf2d6684439f16d89e8d0c957877e2e542.jpeg)

---

<div class="post-metadata">

**Author:** ![HB\_1](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@HB\_1](https://discourse.nodered.org/u/HB_1)\
**Post date:** [21 April 2023 11:06 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/10 "2023-04-21T11:06:21Z")

</div>

Thanks @jbudd solved the issue

---

<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:** [20 June 2023 11:07 UTC](https://discourse.nodered.org/t/retrieve-values-from-payload-object/77764/11 "2023-06-20T11:07:19Z")

</div>

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