@3DJupp,
Here’s a runnable rule that’ll extract it. You can use it to try other combo’s as well:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
rule "JSON Test"
when
Time cron "0/10 * * * * ?"
then
var String json = '{"data":[{"active":true,"analysed":1,"done":6.8686644224222713,"job":"Desk_Organizer_new","jobid":55,"linesSend":29055,"name":"P802M","ofLayer":377,"online":1,"paused":false,"printTime":37158.890468541649,"printedTimeComp":8028.750444368286
5,"slug":"P802M","start":1473748027,"totalLines":423008}]}'
var String type = transform("JSONPATH", "$.data[0].job", json)
logInfo("json", type)
end
I might follow the advice from Mark, because it could be, that i have to do some calculations within the rule.
Regex will work, of course.
The “Json Test” works great, if i handle the items as string items.
What if i want to extract a Float or Integer value?
(For example the percentage called “done”)
If all you want is the number then just assign it to a Number Item. If you want to do math with it in your rule use Float::parseFloat(are) which returns a float primitive.
If the String being parsed can ever have a decimal in it you must use Float. Integer::parseInt will throw an exception if it encounters a decimal point.