# Getting a value from json for a gauge

**URL:** <https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728>\
**Category:** General\
**Created:** [29 November 2020 19:14 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728 "2020-11-29T19:14:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wingnut/32/32851_2.png) [@Wingnut](https://discourse.nodered.org/u/Wingnut)\
**Post date:** [29 November 2020 19:14 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/1 "2020-11-29T19:14:51Z")

</div>

I'm new to this, so much to learn with Home Assistant, Tasmota, Grafana and now Node Red.

I'm trying to construct a Node Red Dashboard to display and control my Owl Intuition Electricity monitor and Central Heating system.

Stuck on how to get the "current power" value out of the json payload to feed into a gague.

The message comes in OK via UDP Multicast node which then goes through a switch node to separate the flows for the 3 different message types. Each then goes through a XML node which puts it into a jsons format (I think).  
Originally I had that output going to the gauge with the path to the element I wanted copied from that element in the debug window. Although the gauge showed the right level the text was the whole thing so I read somewhere to get just the value I wanted by a function node.  
So I put the path into the function but I get the error that it is returning a string.  
What am I doing wrong?  
My line in the function is:

```auto
return msg.payload.electricity.chan[0].curr[0]._;

```

The payload it's trying to read is:

```auto
{"electricity":{"$":{"id":"443719002FAD"},"timestamp":["1606673600"],"signal":[{"$":{"rssi":"-53","lqi":"12"}}],"battery":[{"$":{"level":"100%"}}],"chan":[{"$":{"id":"0"},"curr":[{"_":"1384.00","$":{"units":"w"}}],"day":[{"_":"19130.05","$":{"units":"wh"}}]},{"$":{"id":"1"},"curr":[{"_":"0.00","$":{"units":"w"}}],"day":[{"_":"0.00","$":{"units":"wh"}}]},{"$":{"id":"2"},"curr":[{"_":"0.00","$":{"units":"w"}}],"day":[{"_":"0.00","$":{"units":"wh"}}]}]}}

```

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [29 November 2020 19:18 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/2 "2020-11-29T19:18:39Z")

</div>

Welcome to the forum.

Have a look here:

> **[Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)**

---

<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:** [29 November 2020 19:36 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/3 "2020-11-29T19:36:01Z")

</div>

A function needs to return an object as the debug node by default wants to read from msg.payload, a string was given, hence the error.

```auto
return {payload:msg.payload.electricity.chan[0].curr[0]._};

```

Personally i find it cleaner with a change node in combination with jsonata (can directly parse it as a number as well), or just extract it like "normal"

 ![Screenshot 2020-11-29 at 20.45.58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f29e23dee332547422b6a821412b469a792ded57.jpeg)

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wingnut/32/32851_2.png) [@Wingnut](https://discourse.nodered.org/u/Wingnut)\
**Post date:** [29 November 2020 20:58 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/4 "2020-11-29T20:58:35Z")

</div>

Brilliant. The first method worked on the example i gave, and on another feeding a graph. Thanks. I will try the second method too as i have many more values to extract.  
So much to learn, and i like to learn by setting myself a project; it would be a lot harder without people like you showing us newbies the way.

---

<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:** [29 November 2020 21:45 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/5 "2020-11-29T21:45:56Z")

</div>

By the way, that isn't JSON, it is a javascript object. JSON is always a string, that can be converted to a js object by feeding it through a JSON node (or vice versa).

---

<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:** [28 January 2021 21:45 UTC](https://discourse.nodered.org/t/getting-a-value-from-json-for-a-gauge/36728/6 "2021-01-28T21:45:59Z")

</div>

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