JSONPATH path not found issue

Hello, I’ve something kinda weird with jsonpath transform in a rule

i’ve a sonoff mqtt item SONOFF_LAMPE_RGB_1_State

Depending on what was its last action, it could be

Case 1

SONOFF_LAMPE_RGB_1_State received update State= {“Time”:“2018-08-23T07:14:10”,“Uptime”:“0T11:24:29”,“Vcc”:3.385,“POWER”:“OFF”,“Dimmer”:100,“Color”:“FF00000000”,“HSBColor”:“0,100,100”,“Channel”:[100,0,0,0,0],“CT”:499,“Scheme”:0,“Fade”:“ON”,“Speed”:1,“LedTable”:“ON”,“Wifi”:

Case 2

SONOFF_LAMPE_RGB_1_State received update State= {“POWER”:“OFF”}

I’ve got error when doing transform(“JSONPATH”, “$.CT”, json) on case 2
that’s ok, could be better if avoidable
But mainly I was expecting this to receive NULL or an empty string, but that’s not the case.

How to detect that the path “CT” is not found by the “JSONPATH” transform ?

Thank you

You may need to get down the Javascript transform route

to be more precise

if json equal {“POWER”:“OFF”} then transform(“JSONPATH”, “$.CT”, json) returns -> {“POWER”:“OFF”}
Isn’t it odd ?

Perhaps I can do something with regular expression like

if (regex 'CT' found in json) then 
     newCT= transform(“JSONPATH”, “$.CT”, json)

If json.contains("CT") 

arfff “knowledge is power” …:hugs:

You could easily switch to a Javascript (JS) transformation. I eliminated the JSONPATH transformation everywhere exactly because of this.

    var result = "none";
    var json = JSON.parse(x);  
        result = json.CT;
        return null;

    return result;