If the value of payload.outside_temp is "null", can I search for this and change it to a value (99) in a change node?
The search/replace option is intended for doing search/replace of text in a property.
You can do what you want using the Expression type in a Set rule:
$exists(payload.outside_temp) ? payload.outside_temp : 99
Got it- thanks!
May be going mad but after upgrading to V1.0.5 I don't get "null" replaced.
Simplified test flow:-
[{"id":"1f20d17d.39c9df","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f08a6cbc.9c38d","type":"debug","z":"1f20d17d.39c9df","name":"Refined","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":893,"y":360,"wires":[]},{"id":"7e16f236.690b1c","type":"change","z":"1f20d17d.39c9df","name":"TeslaOutsideTemp","rules":[{"t":"set","p":"payload.outside_temp","pt":"msg","to":"$exists(payload.outside_temp) ? payload.outside_temp : 99","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":659,"y":280,"wires":[["f08a6cbc.9c38d"]]},{"id":"4554116.8edc4f","type":"inject","z":"1f20d17d.39c9df","name":"Inj Null","topic":"","payload":"{\"outside_temp\":null}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":280,"wires":[["7e16f236.690b1c","9e42afc8.6400e"]]},{"id":"9e42afc8.6400e","type":"debug","z":"1f20d17d.39c9df","name":"TestRaw","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":629,"y":360,"wires":[]},{"id":"26a1737a.46ff9c","type":"inject","z":"1f20d17d.39c9df","name":"Inj12","topic":"","payload":"{\"outside_temp\":12}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":360,"wires":[["9e42afc8.6400e","7e16f236.690b1c"]]}]
The definition of $exists at http://docs.jsonata.org/boolean-functions.html says
Returns Boolean true
if the arg expression evaluates to a value, or false
if the expression does not match anything (e.g. a path to a non-existent field reference).
Presumably null is treated as a value. so true is returned. If the payload does not contain an attribute of that name then false is returned.
Little break, head cleared- $boolean(payload.outside_temp) ? payload.outside_temp : 99 handles correctly.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.