Filter values out of a msg - this has got to be simple!

2,379 views
Skip to first unread message

Ben Post

unread,
Aug 25, 2016, 2:30:43 AM8/25/16
to Node-RED
what exactly do I write in function node to filter out wspd, gust and wdir from the following message??

thanks!
msg : Object{ "_msgid": "ec5f5f5d.13a0a", "topic": "", "payload": "", "observation": { "key": "94614", "class": "observation", "expire_time_gmt": 1472112000, "obs_id": "94614", "obs_name": "Swanbourne", "valid_time_gmt": 1472104800, "day_ind": "D", "temp": 18, "wx_icon": null, "icon_extd": null, "wx_phrase": null, "pressure_tend": null, "pressure_desc": null, "dewPt": 5, "heat_index": 18, "rh": 43, "pressure": null, "vis": null, "wc": 18, "wdir": 50, "wdir_cardinal": "NE", "gust": null, "wspd": 15, "max_temp": null, "min_temp": null, "precip_total": null, "precip_hrly": null, "snow_hrly": null, "uv_desc": "Moderate", "feels_like": 18, "uv_index": 4, "qualifier": null, "qualifier_svrty": null, "blunt_phrase": null, "terse_phrase": null, "clds": null, "water_temp": null, "primary_wave_period": null, "primary_wave_height": null, "primary_swell_period": null, "primary_swell_height": null, "primary_swell_direction": ....



ghe...@me.com

unread,
Aug 25, 2016, 2:55:10 AM8/25/16
to Node-RED
You should be able to do it without a function node
Assuming you want to extract the values for these two items

====>SPLIT_NODE======================>SWITCH_NODE======>
          with the split set to the                                   with property set to msg.parts.index
           item wanted ie wspd                                     and switch item set to == " type" number 1

so for wspd should return 15

I think

Alisdair Smyth

unread,
Aug 25, 2016, 2:59:34 AM8/25/16
to Node-RED
Within a function node, 
delete msg.observation.wspd;
delete msg.observation.gust;
delete msg.observation.wdir;

Alternatively you could use the change node, and implement three "delete" rules.  One for each property you don't want - msg.observation.wspd, msg.observation.gust and msg.observation.wdir. 

Ben Post

unread,
Aug 25, 2016, 4:39:20 AM8/25/16
to Node-RED
Thanks, sorry my request was poorly worded. How do I pick out only those fields "wspd", "gust" etc.?

a filter node would be nice!?

Cheers

Nicholas O'Leary

unread,
Aug 25, 2016, 5:23:29 AM8/25/16
to Node-RED Mailing List
Hi Ben,

what do you want the resulting message to look like? Do you still want msg.observation to exist, but just have those three properties in it? For example:

{ "_msgid": "ec5f5f5d.13a0a", "topic": "", "payload": "", "observation": { "wspd": 123, "gust": null, "wdir":50} }


In a function node you could do:


  var observation = {
      wspd: msg.observation.wspd,
      gust: msg.observation.gust,
      wdir: msg.observation.wdir
  }
  msg.observation = observation;
  return msg;


Nick



--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Ben Post

unread,
Aug 25, 2016, 5:48:02 AM8/25/16
to Node-RED
There it is, thanks very much!
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Henrik Kamvåg

unread,
Aug 25, 2016, 4:12:06 PM8/25/16
to Node-RED
I'd just use the switch node and use '== msg.payload.wspd', '== msg.payload.gust', '== msg.payload.wdir' and finaly a 'otherwise'.
Now they are all filtered and the rest is tossed. 

Henrik Kamvåg

unread,
Aug 25, 2016, 4:13:48 PM8/25/16
to Node-RED
Use the switch tool. Sort on your properties and finnish of with a 'otherwise'.


Den torsdag 25 augusti 2016 kl. 08:30:43 UTC+2 skrev Ben Post:

Nicholas O'Leary

unread,
Aug 25, 2016, 4:15:28 PM8/25/16
to Node-RED

Henrik,

The Switch node does not remove properties from a message. It doesn't help in this scenario.

Nick


Ben Post

unread,
Aug 25, 2016, 8:55:28 PM8/25/16
to node...@googlegroups.com
Inline images 1

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/Z8f10vkc8JA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.

sebasti...@gmail.com

unread,
Sep 7, 2016, 6:26:09 AM9/7/16
to Node-RED
Reply all
Reply to author
Forward
0 new messages