this is my first topic and I hope I’m doing it right.
I try to ready out some data from a Opendata JSON file. The read out works fine, but I don’t now how to read out the latest entry on the file. they just add the newest entry (result.) at the end (highest number). so I want to read out the highest result…
rule “Wasser & Luft - Tiefenbrunnen” // all 15 min
when
Time cron "0 0/15 * 1/1 * ? * "
then
var String data = sendHttpGetRequest(“https://tecdottir.herokuapp.com/measurements/tiefenbrunnen”)
var String varWaTi1 = transform (“JSONPATH”, “$.result.[0].values.timestamp_cet.value”, data)
var String varWaTi2 = transform (“JSONPATH”, “$.result.[0].values.air_temperature.value”, data)
var String varWaTi3 = transform (“JSONPATH”, “$.result.[0].values.humidity.value”, data)
var String varWaTi4 = transform (“JSONPATH”, “$.result.[0].values.water_temperature.value”, data)
WaLu_Tiefenbrunnen_01.sendCommand(varWaTi1)
WaLu_Tiefenbrunnen_02.sendCommand(varWaTi2)
WaLu_Tiefenbrunnen_03.sendCommand(varWaTi3)
WaLu_Tiefenbrunnen_04.sendCommand(varWaTi4)
logInfo(“Wasser & Luft - Tiefenbrunnen”, varWaTi4)
end
so by the JASONPATH after the result. it should count up and take the highest number. but how can I manage it. it’s probably easy going, but I’m totally new here…
How to count elements in a JSON array is shown here
If you only want the last element, you need not iterate but can go to it directly.
Remember elements start at zero, so the last element of an array with length 17 is [16].