Improving Parsing Security camera JSON data


I have a zoneminder system that sends motion data to node red via MQTT. Currently I parse that data with a function node. A while back I read that using function nodes isn't very efficient. What I'm looking to do is create a node that detects a person in a specific zone. Here is an example of the object:

{"hookvalue":"0","state":"alarm","detection":{"labels":["bus","car","person"],"boxes":[[211,106,693,546],[92,94,434,340],[240,226,274,314]],"image_dimensions":{"original":[480,704],"resized":[545,800]},"frame_id":"snapshot","confidences":[0.809855103492737,0.596688449382782,0.339584589004517]},"eventtype":"event_start","monitor":"14","name":"Driveway Substream:(614864) [s] detected:bus:81% car:60% person:34%  Motion","eventid":"614864"}

Is there a better way than through a function node?

What part of the data tells you it is a person?

Also show us the Function you are using. Copy/paste the text from the function node please. Then we will be able to see what you need.
The overheads of using a function are not large so unless you are running it thousands of times a second (or dozens of times a second on a Pi Zero) then I would not worry about it.

@zenofmud there is a key in the JSON object called "detection" also a key called "confidences"

Here is the function:

var stuff = msg.payload;
if (stuff.detection.confidences > 0.60){
    var myname =
    var splitname = myname.split(":");
    if(splitname[2] == "person"){
        var contentstr = "The " + splitname[0] + " camera has indicated a person moving within it's field of view.  The Id is:  " + stuff.eventid + "" + stuff.eventid + "&fid=snapshot&width=600&username=****&password=***"

        msg.payload = { 

            type: "message",
            title: "Camera system motion",
            chatId: Mychatid,
            content: contentstr,

return msg;

Eventually I'd like to add variables to change the confidence required to send a message, for now though I'm trying to get it a little more "dialed"

Your function node seems to have some errors, notice line 7 has a red x.

1)What version of NR and node.js are you running? (you can find this in the startup log)
2) notice all the items underlined. That is because those items have not been defined.
3) where is Mychatid coming from?
4) what are you attempting to do with the new = ... line?
5)What do you want the end result of the function node (or replacement) to look like?

@zenofmud thanks for looking into this. I changed a couple pieces of the code for security purposes. So line 13 where it lists "Mychatid" would actually be the chat id for telegram. On line 7 I substituted the asterisks for my actual user name and password, again for security purposes. As far as the 4th question I don't see a line containing "new =". As far as you question 5, that's really my question. Is there a better way to send messages based on if the JSON payload from Zoneminder has detected a person within a certain percentile?

Assuming you have it working with code in a function node, why would you change? Maybe it would be possible to break up things and use a number of standard nodes in line, but why? If you do not run into any performance issues and the notification is fast enough, I would not change.

With the code you have full control of what is happening. I assume, it looks that way, you also grab and send an image as attachement. With the code you are preparing the message that is sent to, I guess, a Telegram node. I do pretty much the same in my setups, works fine and good enough.