# Improving Parsing Security camera JSON data

**URL:** https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104
**Category:** General
**Created:** [9 April 2024 15:24 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104 "2024-04-09T15:24:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![lorenjz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lorenjz/32/35952_2.png) [@lorenjz](https://discourse.nodered.org/u/lorenjz)
#### Post date: [9 April 2024 15:24 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/1 "2024-04-09T15:24:45Z")

</div>

Hello,

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:

```auto
{"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?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [9 April 2024 15:31 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/2 "2024-04-09T15:31:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [9 April 2024 15:43 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/3 "2024-04-09T15:43:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![lorenjz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lorenjz/32/35952_2.png) [@lorenjz](https://discourse.nodered.org/u/lorenjz)
#### Post date: [9 April 2024 19:03 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/4 "2024-04-09T19:03:18Z")

</div>

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

Here is the function:

```auto
var stuff = msg.payload;
if (stuff.detection.confidences > 0.60){
    var myname = stuff.name
    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 + " https://zimmhomecam.net/zm/index.php?view=image&eid=" + stuff.eventid + "&fid=snapshot&width=600&username= ****&password=***"
        view=image&eid=9666&fid=objdetect&width=600&username= ******&password=xxx****   

        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"

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [9 April 2024 20:02 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/5 "2024-04-09T20:02:13Z")

</div>

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

 ![Screenshot 2024-04-09 at 4.01.12 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2ffd05e0fcb1b8aaaa68d8071c2ac180f0a00298.png)

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?

---

<div class="post-metadata">

### Author: ![lorenjz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lorenjz/32/35952_2.png) [@lorenjz](https://discourse.nodered.org/u/lorenjz)
#### Post date: [16 April 2024 01:50 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/6 "2024-04-16T01:50:17Z")

</div>

@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?

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [16 April 2024 05:42 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/7 "2024-04-16T05:42:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [15 July 2024 05:42 UTC](https://discourse.nodered.org/t/improving-parsing-security-camera-json-data/87104/8 "2024-07-15T05:42:52Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
