Good luck. I’ve been there and it never was reliable enough.
Chain a REGEX transformation in frond of the JSONPATH. Only if the REGEX matches will the message get passed on to the JSONPATH, effectively filtering out those messages that the JSONPATH can’t handle. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters