Need help with JsonPath Transformation

Hello people,
I am trying to interpret a status with the http binding via json. Unfortunately without success until now:
This is how I built it:

thing:

Thing http:url:chickencoop "Hühnerstall Tür" @ "Hühnerhaus"[ 
	baseURL="http://XXX.XXX.XXX.XX:8002",
	username="admin",
	password="meinPasswort",
	refresh=15] {
		Channels:
        Type switch : ChickenDoor_up    [stateExtension="/relay/1/Status", stateTransformation="JS:shelly.js", commandExtension="/relay/1?turn=%2$s", onValue="on", offValue="off"] //runter
        Type switch : ChickenDoor_down  [stateExtension="/relay/0/Status", stateTransformation="JS:shelly.js", commandExtension="/relay/0?turn=%2$s", onValue="on", offValue="off"] //rauf
    }

shelly.js

(function (x) { 
    var json = JSON.parse(x); 
    return json.ison.value == "true" ? "ON" : "OFF"
})(input)

the response when I retrieve XXX.XXX.XX:8002/relay/0/status:

{"ison":false,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"overpower":false,"overtemperature":false,"is_valid":true,"source":"timer"}

I don’t know where the error could be…
But surely someone from the community :wink:

Looking at the code I would try …

return json.ison == true ? ....

Or maybe

return json.ison == "true" ? ...

The value isn’t needed and looking at the json message the ison doesn’t contain a string (and quotes). If this doesn’t work maybe try to post the error in the openhab.log. Usually this helps to identify the error.

When the transformation returns the full string, it indicates an error in the transform. I would expect to see something in the logs.

In this case, I don’t think the .value is right. Shouldn’t it be just json.ison?

Also, in JavaScript I believe when you have an operation as the condition, you need to put it in parens.

return (json.ison == true) ? "ON" : "OFF"

But, like @supersjel notices, in the JSON string the boolean isn’t in quotes so it should be a boolean in the parsed json Object

return json.ison ? "ON" : "OFF"

This is a simple JSON string without arrays so the JSONPATH transformation might be more appropriate. Then the definition of the transform exists inline instead of needing to exist in another file.

JSONPATH:$.ison

You can using the onValue/offValue parameters to map the true/false to ON/OFF.

is nothing in the logs

I tried this but it does not work.

I tried it as well like this:

        Type switch : ChickenDoor_up    [stateExtension="/relay/1/Status", stateTransformation="JSONPATH:$.ison", commandExtension="/relay/1?turn=%2$s", onValue="on", offValue="off"] //runter

But also not work

And i don’t really understand this.
Can you give me an example?

Ok, maybe a step back. To use jsonpath and js transformations you have to install some add-ons if I remember well. Long time ago, you tend to forget these things. Ring a bell?

onValue='true' and offValue='false' also needs to be there. Those fields take the output from the transform and maps them to ON/OFF for you.

Indeed, the JSONPATH transform must be installed. But there will be errors in the logs telling you this.

like this?

        Type switch : ChickenDoor_up    [stateExtension="/relay/1/Status", stateTransformation="JSONPATH:$.ison", onValue='true', offValue='false' commandExtension="/relay/1?turn=%2$s", onValue="on", offValue="off"] //runter

that can’t be right, that the on and offValue is defined 2 times…

I have installed both:
Javascript Transformation
and
JSONPath Transformation

No, you’ve now have onValue and offValue defined twice.

Correct. You need to replace the properties that are there, not define them again.

This is why I hate .things files. So much time spent chasing syntax errors that are impossible to make through the UI.

A lot of these errors should show up in the logs as errors. Loading your .things file should show errors because of the duplicate properties. The JS Transform should have shown errors because of the .value.

Also, on some bindings you have to restart OH to pick up changes to .things files. Are you certain you are even running with these changes?