# Node -red filtering

**URL:** https://discourse.nodered.org/t/node-red-filtering/54278
**Category:** General
**Created:** [25 November 2021 15:09 UTC](https://discourse.nodered.org/t/node-red-filtering/54278 "2021-11-25T15:09:26Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 15:09 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/1 "2021-11-25T15:09:27Z")

</div>

hi guys  
i am not so good in NodeJs,  
please how can i filter the the messages so that i will only debug few of the messages  
the messages are `{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}`

i want to display these values

```auto
1."load_state"
2."bat_v"
3."load_w"
3. "bat_temp"

```

i did this

```auto
const values = [
  {
    "load": `${msg.payload.load_w}`
  }
  ]
  msg.payload=values;
  return msg;

```

but my result is `load: "undefined" `  
thanks fro your help !

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 15:26 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/2 "2021-11-25T15:26:34Z")

</div>

@knolleary

---

<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: [25 November 2021 15:30 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/3 "2021-11-25T15:30:06Z")

</div>

Please try to not tag individual users in posts - particular when bumping a post that hasn't been replied to as quickly as you'd like.

Given your previous question about parsing the JSON to a JavaScript object, are you sure you're passing the parsed object into this function node?

Add a debug node next to the function node so you can check exactly what the message looks like that is being passed into the Function - is `msg.payload` an object or string?

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 15:34 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/4 "2021-11-25T15:34:19Z")

</div>

> [@knolleary](#):
>
> object

Thank you very much.  
i will not next time.  
both string and object

---

<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: [25 November 2021 15:36 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/5 "2021-11-25T15:36:14Z")

</div>

> [@AYo](#):
>
> both string and object

A single property cannot be both things. Can you share a screenshot of the debug sidebar showing us what you are passing into the Function node.

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 15:44 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/6 "2021-11-25T15:44:31Z")

</div>

thanks Knolleary,

here are the screenshots

the message i got from the debug node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f304a4fc77d2bc468b88de2c95e4646d68af53d5.png)

the function node before the debug node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7b10a9d815a4fa0c06a027b9f5c415e7d70f701a.png)

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

the node all together

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55f82b54781b2118bfded0f2fb1b3212b3953aa7.png)

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

---

<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: [25 November 2021 15:47 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/7 "2021-11-25T15:47:28Z")

</div>

You have shown a screenshot of the Debug sidebar for the message coming _out_ the Function node - that doesn't help us. You've already told us it isn't what you want.

What we need to see is the message you are passing _in_ to the Function node. That's the only way we can help you get the Function code right.

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 15:53 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/8 "2021-11-25T15:53:12Z")

</div>

oh ok  
this is the message passing through the node

```auto
{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

```

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

---

<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: [25 November 2021 16:02 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/9 "2021-11-25T16:02:56Z")

</div>

There’s a great page in the docs 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)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

Once you get the path then you can use that in a Change node to Move that item To msg.payload.

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 16:10 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/10 "2021-11-25T16:10:30Z")

</div>

thanks alot.  
so useful !!!!

---

<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: [25 November 2021 16:12 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/11 "2021-11-25T16:12:20Z")

</div>

> [@AYo](#):
>
> this is the message passing through the node

You have posted two things there, the first is a copy/paste of a javascript object containing the data, the second is a screenshot supposedly of that same data. However the screenshot shows that the data is in the first element of an array in msg.payload. The copy/paste object is not in an array. You need to decide which one of those is the real data.

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 16:13 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/12 "2021-11-25T16:13:27Z")

</div>

this is the real data

```auto
{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

```

---

<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: [25 November 2021 16:26 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/13 "2021-11-25T16:26:01Z")

</div>

In that case why did it show as in an array in the screenshot

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5094b714f9bdd4bc725dcde7dde069c7a0f55f34.png)

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 16:29 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/14 "2021-11-25T16:29:18Z")

</div>

i am not so sure i just copied the value from debugged message.

```auto
[{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}]

```

---

<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: [25 November 2021 16:33 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/15 "2021-11-25T16:33:43Z")

</div>

Now you are showing it in an array (it has the `[...]` around it). Presumably you missed those out when copying it the first time.

---

<div class="post-metadata">

### Author: ![AYo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ayo/32/50481_2.png) [@AYo](https://discourse.nodered.org/u/AYo)
#### Post date: [25 November 2021 16:41 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/16 "2021-11-25T16:41:40Z")

</div>

oh i see.

---

<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 December 2021 16:42 UTC](https://discourse.nodered.org/t/node-red-filtering/54278/17 "2021-12-09T16:42:09Z")

</div>

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