Extract Data from Many Array

Hello, i'm still fresh with node-red, i had trouble of extracting array data to csv, i did extract some of it but not all of them, this my array data

What i've done

var arrData = msg.payload.results[0].series[0].values[0];
sensorData1 = [String(arrData[0]),String(arrData[1])]
msg.payload = String(sensorData1)
return msg;

This is the result

1544083448366,290.02

The result is what i expected but the trouble is, the array data is too much, it can reach thousand in some condition, it will be impossible to using my code above, is anybody can suggest how to do this ? Thank you.

Hi, there are many possible ways to do such data transformation. When it comes to large and complex datasets my personal preference is to use a jsonata expression. We could help you better if you manage to export your dataset to a text file and share this file with us. You can use a pair of nodes like below to save the msg.payload to a file in your system. Just make sure to edit the file node to use a valid folder from your computer.

[{"id":"3f42a918.278f56","type":"json","z":"862de1fd.259ca","name":"","property":"payload","action":"str","pretty":false,"x":470,"y":160,"wires":[["c7654a2.10ddbb8"]]},{"id":"c7654a2.10ddbb8","type":"file","z":"862de1fd.259ca","name":"Save JSON","filename":"C:\\Users\\OCM\\.node-red\\static\\nrfiles\\dataset.json","appendNewline":true,"createDir":false,"overwriteFile":"true","x":630,"y":160,"wires":[["6720364b.7442c8"]]}]

Hy! I am new to Node-red and java script, I need some help. I am using a Wifi node to know the wifi strength of all the available networks. Some times i get one to two objects (networks) some times i get 10-15 (objects) based on network available. I only wants to read the signal_level value of SSID of "TCF" (as i am connected to TCF wifi). How can i achieve this task? Is is possible to filter only TCF and ignore rest of SSID

Your question is not really related to the original question of this thread, so would have been better on a new thread. However, if you feed that through a Split node you will get one message for each entry in the array, follow that with a Switch node that only passes messages if the SSID is what you want, then you can use a Change node to pick up the signal level into msg.payload.

Since you are new to node-red I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour. A small investment for a lot of gain.

Also, when it comes to decoding messages, there is a great page in the docs (Working with messages : Node-RED) 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

And finally just to note that what you have showed is not JSON it is a javascript object. JSON is always a string. This post should help to clarify the difference between Javascript objects and JSON.

Wow, that is three canned messages in one post, I think that is a record for me :slight_smile:
If you have further questions on this could you start a new thread with a relevant title please. I will close this one.

1 Like