Null check within json in JS Rule


how do I check if a json value is null correctly within a JS rule?

here is the json example

"session": {
"valid": true,
"totp": false,
"sid": null
"csrf": null
"validity": 300

and my try:

actions.Transformation.transform("JSONPATH", "$.session.sid", response) != null

and the error is

Failed to execute rule pihole API rule: TypeError: Cannot read property "toString" from null: TypeError: Cannot read property "toString" from null

Any help appreciated :slight_smile:

JSON stands for “JavaScript Object Notation”. You don’t need to use the transform for this. Just parse it directly into an Object and then use it.

var data = JSON.parse(response);
if(data.session.sid === null) ...