[SOLVED] JsonPath Transformation Service in OpenHAB 2.5 broken?

Hi,

I had a working rule using a HTTP request to get a JSON String which was then deconstructed into various values. After upgrading to OpenHAB 2.5 it stopped working as type conversions failed. I was able to boil it down to the following issue:

...
var String Json_sb = sendHttpGetRequest("http://...")
var String Consumption_W = transform("JSONPATH", "$.Consumption_W", Json_sb) 
logInfo("gn.rules", "This is the output:" + Consumption_W)
...

resulting in the log entry

2019-12-22 23:31:00.031 [INFO ] [smarthome.model.script.gn.rules] - This is the output:{"Apparent_output":226,"BackupBuffer":"0","BatteryCharging":false,"BatteryDischarging":false,"Consumption_W":395,"Fac":50,"FlowConsumptionBattery":false,"FlowConsumptionGrid":true,"FlowConsumptionProduction":false,"FlowGridBattery":false,"FlowProductionBattery":false,"FlowProductionGrid":false,"GridFeedIn_W":-400,"IsSystemInstalled":1,"OperatingMode":"2","Pac_total_W":-5,"Production_W":0,"RSOC":7,"Sac1":75,"Sac2":75,"Sac3":76,"SystemStatus":"OnGrid","Timestamp":"2019-12-22 23:31:00","USOC":0,"Uac":230,"Ubat":48}

It looks like the JsonPath Transformation Service stopped working as the whole JSON string is assigned to the variable Consumption_W, instead of the proper result 395.

Any ideas?
Best, 
Thomas

Try uninstalling the transformation, clean the cache, restart OH, and reinstall the transformation.

Thanks for the hint. Executing your advice I discovered that the JSONPath Transformation was uninstalled (for whatever reason). Reinstallted it - and everything is fine again :slight_smile:

Glad I could help.:smiley:

Please click the square box on the post that provided the solution to mark topic as solved.
Thanks

Hallo,

sorry for opening this box again. But do have the same issue as above and altough I follwed the advice:

I may have overlooked something, but I still spend a lot of time without progress.

That’s the rule I created:

var AC_WZ_URL           = 'http://XXX.XXX.XXX.XXX/api.cgi'
var AC_WZ_json          = '{"command":"login","data":{"username":"XXXX","password":"XXXXX"}}'
var ID


rule "logIn"
when
    Item ReqLogIn received command
then
        ID=sendHttpPostRequest(AC_WZ_URL, "application/json",AC_WZ_json )
         logInfo("AC.rules", "POST_Response ID: {}",  ID)
        var String out = transform("JSONPATH", "$[data][id][sessionID]", ID)    //check for transformation http://jsonpath.com/
         logInfo("AC.rules", "POST_Response out: {}",  out)                     // Logging for debugging
        sessionsID.postUpdate(out)
end

But I still face the issue the data passed trough without JSONPATH transformation.

The corresponding log looks:

==> /var/log/openhab2/openhab.log <==
2020-06-22 10:36:34.606 [INFO ] [ipse.smarthome.model.script.AC.rules] - POST_Response ID: {"success":true,"data":{"id":{"sessionID":"A7KA0O88VValqK25Dt4AHB3kS76oHqZ"}}}
2020-06-22 10:36:34.610 [INFO ] [ipse.smarthome.model.script.AC.rules] - POST_Response out: {"success":true,"data":{"id":{"sessionID":"A7KA0O88VValqK25Dt4AHB3kS76oHqZ"}}}

==> /var/log/openhab2/events.log <==
...
2020-06-22 09:57:00.466 [thome.event.ExtensionEvent] - Extension 'transformation-jsonpath' has been uninstalled.
...
2020-06-22 10:03:38.019 [thome.event.ExtensionEvent] - Extension 'transformation-jsonpath' has been installed.
...
2020-06-22 10:36:34.614 [vent.ItemStateChangedEvent] - sessionsID changed from {"success":true,"data":{"id":{"sessionID":"5g6nzoZ26kjXQ5muYj5i4N2IC9e92Zb"}}} to {"success":true,"data":{"id":{"sessionID":"A7KA0O88VValqK25Dt4AHB3kS76oHqZ"}}}

Could anyone advice how to proceed?

BR
Andreas

The behaviour of transformation services is by design to return the whole input in case of error.

I’d have thought you should have something more like
$.data.id.sessionID

Thank you, this was the magic!

I used jsonpath.com and the related explanation in https://goessner.net/articles/JsonPath/index.html#e2.

According to that, JSONpath allows “. or []” as child operator…
Obviously I took exactly an option, being not implemented in the transformation!

Thank you very much for the hint!
BR
Andreas

Yes, “JSONPATH Transformation Service” is not regular JSONPATH

Here are the docs, with examples

For anyone else who comes along this problem Check if the service is installed:
PaperUI -> Addons - Transformations -> JSONPATH -> Install