Jython json transform jsonpath

language: JYTHON rule
trying out sendHttpGetRequest. the result is json.
Guess I have to use "transform and JSONPATH to get the individual values in json string.
what do I need to import?

Assuming you are using the helper libraries, all the core Actions are documented here.

from core.actions import Transformation
Transformation.transform("JSONPATH", "$.test", test)

One way is to import json. This works for me. Note the “json.loads(response)” to get it into a dictionary. See https://www.w3schools.com/python/python_json.asp

from core.rules import rule
from core.triggers import when
from core.actions import HTTP
import json

@rule("Filtrete Thermostat Update", description="Picks up Filtrete thermostat status", tags=[])
@when("Time cron 37 * * * * ?")
def thermostatCollectData(event):

    response = HTTP.sendHttpGetRequest("", 10000)
    # thermostatCollectData.log.info(response)
    jsonResponse = json.loads(response)

    events.postUpdate("Tstat_state", str(jsonResponse["tstate"]))

thanks! tried to search (google, search function on the site), didn’t find it.
I’ll try this and the other answer…

great, I’ll try this answer too :slight_smile:

In openHAB 3.4 this is not working anymore:

ImportError: cannot import name Transformation in /etc/openhab/automation/jsr223/python/personal/speedtest.py at line number 6

See here for a solution.