# Extract object value

**URL:** <https://discourse.nodered.org/t/extract-object-value/67530>\
**Category:** General\
**Tags:** function-node\
**Created:** [9 September 2022 18:50 UTC](https://discourse.nodered.org/t/extract-object-value/67530 "2022-09-09T18:50:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 18:50 UTC](https://discourse.nodered.org/t/extract-object-value/67530/1 "2022-09-09T18:50:16Z")

</div>

Hello, can me someone explain me how i can extract the value temperature from the following payload?

I tried with a change node but it doesnt work. I can extract the value from the array meters, but not the temperature value. Can someone give me a example for a syntax please?

```auto
msg : Object
object
payload: object
topic: ""
_msgid: "84c5eb0c.4365a8"
status: object
wifi_sta: object
cloud: object
mqtt: object
time: "20:42"
serial: 1
has_update: false
mac: "xxxxxxxxxx"
relays: array[1]
meters: array[1]
temperature: 25.23
overtemperature: false
update: object
ram_total: 50832
ram_free: 39616
fs_size: 233681
fs_free: 171684
uptime: 10387

```

Thx for help

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 September 2022 18:54 UTC](https://discourse.nodered.org/t/extract-object-value/67530/2 "2022-09-09T18:54:15Z")

</div>

As you have not used the copy value button in the debug side panel, the object you have shown is confusing.  
I believe the correct path is `msg.temperature`.

If you use the debug panel and hover to side of object name 2 icons appear, one is copy value, the other copy path. Both very helpful.  
The copy value icon/button would give you a correctly formated object, and it would be easier to see the correct object structure.

---

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 18:57 UTC](https://discourse.nodered.org/t/extract-object-value/67530/3 "2022-09-09T18:57:21Z")

</div>

> [@E1cid](#):
>
> As you have not used the copy value button in the debug side panel, the object you have shown is confusing.  
> I believe the correct path is `msg.temperature`.
> 
> If you use the debug panel and hovber to side of object name 2 icons appear, one is copy value, the other copy path. Both very helpful

Hi and thanks at first

I tried to copy the hole object with the button in the debug panel

i hope it`s better now

```auto
{"_msgid":"5e7881f7.f5cd2","payload":{"relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662756933,"counters":[0,0,0],"total":2397}]},"topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxxx","ip":"xxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"20:55","serial":1,"has_update":false,"mac":"xxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662756933,"counters":[0,0,0],"total":2397}],"temperature":25.23,"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":40224,"fs_size":233681,"fs_free":171684,"uptime":11191}}

```

---

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 18:59 UTC](https://discourse.nodered.org/t/extract-object-value/67530/4 "2022-09-09T18:59:26Z")

</div>

If i try msg.temperature i`ve got this.....

```auto
{"_msgid":"35ed5510.63a5ba","topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxxxxx","ip":"xxxxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"21:01","serial":1,"has_update":false,"mac":"xxxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662757279,"counters":[0,0,0],"total":2397}],"temperature":25.23,"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":40064,"fs_size":233681,"fs_free":171684,"uptime":11537}}

```

but i wan`t only the value

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 September 2022 19:04 UTC](https://discourse.nodered.org/t/extract-object-value/67530/5 "2022-09-09T19:04:16Z")

</div>

It is `msg.status.temperature`  
which you can find using the copy path button, and appending `msg.` to the front

 ![chrome_screenshot_1662750754125](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e036d367dbb1477eba3f1ab9e6e2d7cce25b129.jpeg)  
hover mouse near where is says copy value and the copy value and path buttons will appear, use the path button to get the path to the adjacent property value.

And here is an example of moving the temperature value to msg.payload, using a change node.

```auto
[{"id":"28100460.a4b09c","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":150,"y":2660,"wires":[["7bbe61b3.327768","1fd9e3b8.9d6dec"]]},{"id":"1fd9e3b8.9d6dec","type":"function","z":"30af2d3e.d94ea2","name":"simulate object","func":"msg={\n \"_msgid\": \"5e7881f7.f5cd2\",\n \"payload\": {\n \"relays\": [\n {\n \"ison\": false,\n \"has_timer\": false,\n \"overpower\": false\n }\n],\n \"meters\": [\n {\n \"power\": 0,\n \"is_valid\": true,\n \"timestamp\": 1662756933,\n \"counters\": [\n 0,\n 0,\n 0\n],\n \"total\": 2397\n }\n ]\n },\n \"topic\": \"\",\n \"status\": {\n \"wifi_sta\": {\n \"connected\": true,\n \"ssid\": \"WLAN-99D921\",\n \"ip\": \"192.168.178.53\",\n \"rssi\": -68\n },\n \"cloud\": {\n \"enabled\": false,\n \"connected\": false\n },\n \"mqtt\": {\n \"connected\": false\n },\n \"time\": \"20:55\",\n \"serial\": 1,\n \"has_update\": false,\n \"mac\": \"E868E7C507FA\",\n \"relays\": [\n {\n \"ison\": false,\n \"has_timer\": false,\n \"overpower\": false\n }\n],\n \"meters\": [\n {\n \"power\": 0,\n \"is_valid\": true,\n \"timestamp\": 1662756933,\n \"counters\": [\n 0,\n 0,\n 0\n],\n \"total\": 2397\n }\n ],\n \"temperature\": 25.23,\n \"overtemperature\": false,\n \"update\": {\n \"status\": \"unknown\",\n \"has_update\": false,\n \"new_version\": \"\",\n \"old_version\": \"20190516-073020/master@ea1b23db\"\n },\n \"ram_total\": 50832,\n \"ram_free\": 40224,\n \"fs_size\": 233681,\n \"fs_free\": 171684,\n \"uptime\": 11191\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2640,"wires":[["84810f46.52a128"]]},{"id":"84810f46.52a128","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.status.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":2640,"wires":[["2e310c13.5e5c1c"]]},{"id":"2e310c13.5e5c1c","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":2680,"wires":[]}]

```

Ignore the function node it is just simulating your msg object.

---

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 19:10 UTC](https://discourse.nodered.org/t/extract-object-value/67530/6 "2022-09-09T19:10:38Z")

</div>

> [@E1cid](#):
>
> msg.status.temperature

I`ve got still this result

```auto
{"_msgid":"1c16882.1c3f878","payload":25.23,"topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxx","ip":"xxxxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"21:08","serial":1,"has_update":false,"mac":"xxxxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662757714,"counters":[0,0,0],"total":2397}],"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":39888,"fs_size":233681,"fs_free":171684,"uptime":11972}}

```

this ist the actual flow i use for testing, maybe it helps you

```auto
[{"id":"10dd93ba.077dec","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"a9a4cecf.d695d","type":"debug","z":"10dd93ba.077dec","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":400,"wires":[]},{"id":"475a1574.c2a66c","type":"inject","z":"10dd93ba.077dec","name":"Poll Status","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":200,"wires":[["404f5a7d.fb0f4c"]]},{"id":"404f5a7d.fb0f4c","type":"shelly-gen1","z":"10dd93ba.077dec","hostname":"xxxxxxxxxx","description":"","mode":"polling","server":"","outputmode":"event","uploadretryinterval":5000,"pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"x":610,"y":420,"wires":[["a9a4cecf.d695d","9665bd31.67ea"]]},{"id":"931b878e.b08448","type":"debug","z":"10dd93ba.077dec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":580,"wires":[]},{"id":"9665bd31.67ea","type":"change","z":"10dd93ba.077dec","name":"","rules":[{"t":"move","p":"status.temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":500,"wires":[["931b878e.b08448"]]}]

```

---

<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:** [9 September 2022 19:21 UTC](https://discourse.nodered.org/t/extract-object-value/67530/7 "2022-09-09T19:21:31Z")

</div>

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 19:29 UTC](https://discourse.nodered.org/t/extract-object-value/67530/8 "2022-09-09T19:29:24Z")

</div>

Sorry, but maybe i didn`t understand

i copied the path directly behind the temperature value but i`ve still got the hole object and not the single value

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94c387d4a6ec4c98de231c5424e2900e9903bdf2.png)

and this is my configuration from the change node

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/1248502a87a39e65069a91fec484031f49b256d9.png)

---

<div class="post-metadata">

**Author:** ![DrS1981](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@DrS1981](https://discourse.nodered.org/u/DrS1981)\
**Post date:** [9 September 2022 20:11 UTC](https://discourse.nodered.org/t/extract-object-value/67530/9 "2022-09-09T20:11:51Z")

</div>

It still doesn`t work - maybe a bug in nodes?

I have no idea anymore

Nobody`s here with any solution?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 September 2022 20:24 UTC](https://discourse.nodered.org/t/extract-object-value/67530/10 "2022-09-09T20:24:47Z")

</div>

You will always get the msg object. But you have moved the temp value now to msg.payload.  
if you moved msg.status.temperature to msg, node-red would produce an error, as msg has to be returned as an object.  
Your debug is set to see the complete object, not just msg.payload.

We can not give a solution as nothing is wrong, You are not understanding message objects and there construction correctly.

---

<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:** [9 September 2022 20:27 UTC](https://discourse.nodered.org/t/extract-object-value/67530/11 "2022-09-09T20:27:55Z")

</div>

> [@DrS1981](#):
>
> I`ve got still this result
> 
> ```auto
> {"_msgid":"1c16882.1c3f878","payload":25.23,"topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxx","ip":"xxxxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"21:08","serial":1,"has_update":false,"mac":"xxxxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662757714,"counters":[0,0,0],"total":2397}],"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":39888,"fs_size":233681,"fs_free":171684,"uptime":11972}}
> 
> ```

There is no msg.status.temperature in that object. How ever in the first object you provided that value does exist.

Is it possible you are getting different data, some with `msg.status.temperature` and some without??

Where is the data coming from?

---

<div class="post-metadata">

**Author:** ![piwi447](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/piwi447/32/67335_2.png) [@piwi447](https://discourse.nodered.org/u/piwi447)\
**Post date:** [10 September 2022 22:09 UTC](https://discourse.nodered.org/t/extract-object-value/67530/12 "2022-09-10T22:09:01Z")

</div>

As said before, the change node is working properly , moving the temperature in the payload property of the message but not creating a new message that would contain only the temperature….  
The tricky thing is that you did not noticed that debug node was configure to display the complete message…

To recreate a new message with the temperature only, you can use a function node.  
I recommend this video that will show you clearly how to [https://youtube.com/watch?v=bovIZtgL68E&feature=share](https://youtube.com/watch?v=bovIZtgL68E&feature=share)

Pierre RUWET

---

<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:** [9 November 2022 22:09 UTC](https://discourse.nodered.org/t/extract-object-value/67530/13 "2022-11-09T22:09:46Z")

</div>

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