According to this Jayway JsonPath evaluator, you could use this JsonPath to return a list of the values you are going for (careful… the json you posted is not in code fences, so it has smart quotes in it)…
$[*][*][0]
Or, if you wanted to get a specific value…
$..[?(@.FraksjonId==7)].Tommedatoer[0]
The functionality of the JSONPATH transformation service has unfortunately been reduced to only allow JSONPATH results that return strings and single element lists. A JSONPATH that returns multiple elements is not supported by the transform. In this case, you would get an error, null or the entire original json, I’m not sure which.
There are other options for this, such as using a JS transform, or pulling the raw data into an item and then calculating the value in a rule using executeCommandLine with jq and updating items. Untested…
import java.util.List
...
// somewhere in your rule
val List<String> trashTimeList = executeCommandLine("/bin/sh@@-c@@/usr/bin/echo " + Raw_Date.state.toString + " | /usr/bin/jq '.[].Tommedatoer[0]'",10000).split("\n")
Thank you for your help. The second transformation example you mentioned, worked as i wanted it to, without any errors. If was supposed to generate a list, it seems to only adopt the first value. I also changed the item from string, to date, so that i can format it as i want in ex. habpanel.
I will add the details on where i’m fetching the data from. I guess this is only usefull for us that live in Norway.
The data source is from a smartphone app, thats called “Min Renovasjon”, published by Norkart AS: https://play.google.com/store/apps/details?id=no.norkart.komtek.renovasjon.client&hl=nb
I got the correct URL by sniffing the traffic that was generated when i chose my address in the app. This is an example of a working curl request:
I edited my previous post to correct something and hopefully to clarify things better. You can’t get a list with more than one element from the JSONPATH transform anymore. And it will now always return a string. Looks like you got it working though!
Actually, instead of your cron job sending the update through MQTT, you could just run the same thing in a rule. And if you’re using a python script, you could just run the result through json.loads, instead of having to deal with a transform.
You really have control on the rules Thank you for your contribution! I Will let you know when i have tested it.
I was on a different path, i was looking into using “sendHttpGetRequest”, but maybe you dont get an output from that?
I was also trying to run the http directly from an item, with " http="<". I was trying with the same JSONPATH in the end, but the error seems to say that only REGEX will work.