How to copy pairs of values from json into to the SQL

Dear all,
With the help of Garmin API I successfully get my Hear rate data into the json file. In JSON file there are pairs of values: EPOCH date/time along with heart rate. My idea is to import this pairs into the SQL.

  1. My JSON file is located on my nodered server.
  2. I know how to import data into the SQL with nodered.
    What I don't know is how to write a loop that will go through json and put epoc and hr data into the variable that I will then pass to the SQL.
    Also please suggest me if the format of the json file is ok, or should I change it?
    hr3.json (8.4 KB)

I am attaching simple json file.

If you want to be able to draw graphs of the historical data then you could consider using influxdb and grafana rather than SQL.

If you use a Change node to extract just the array of timestamp/rates into msg.payload, and then feed that through a Split node, you will get a stream of messages with individual records, which you can then insert into the database.

1 Like

You're right, influxdb is more appropriate for this scenario, but since I am already having SQL in place, I somehow got used to SQL but I am representing the data in Grafana.
In the meantime I already sucesfuly parsed the json into the object.

Now I am planning to use function node and while loop node to go through all hearRateValues and for each write it to the SQL.
Can you please suggest me, how to get the highest value of hearratevalue array, because I need for a while loop condition.
Thank you in advance. In above example it is 386. How can I get this 386?

Don't do that, use a Change and Split node as I suggested.

If you did want to do it in a function then use Array.forEach(). But don't, use the core nodes, it is much easier.
If you do ever need the length of an array it is Array.length

Colin I was listening you suggestion and I did it as you suggested. It is doing very nice...exactly what I was looking for. Thank you very much.


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