# Help trying to extract object attribute

**URL:** <https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357>\
**Category:** General\
**Created:** [5 October 2019 17:51 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357 "2019-10-05T17:51:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subjectbit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subjectbit/32/12855_2.png) [@subjectbit](https://discourse.nodered.org/u/subjectbit)\
**Post date:** [5 October 2019 17:51 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/1 "2019-10-05T17:51:35Z")

</div>

Hi all -

I'm trying to implement a facial recognition workflow that announces who has entered an area after image processing is applied via Facebox. I've gotten Facebox to work fine and see attribute object passed in the complete message payload, but can't for the life of me figure out how to actually use it.

My thought was to use a switch node to check for the specific attribute and then route the announcement accordingly. [Pastebin of the flow here](https://pastebin.com/RspjVKPc)

The specific object value I'm trying to base the switch node off of is _data.attributes.matched\_faces_

Any suggestions?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [5 October 2019 17:53 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/2 "2019-10-05T17:53:21Z")

</div>

Can you post a sample message that is going into that switch?

---

<div class="post-metadata">

**Author:** ![subjectbit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subjectbit/32/12855_2.png) [@subjectbit](https://discourse.nodered.org/u/subjectbit)\
**Post date:** [5 October 2019 18:02 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/3 "2019-10-05T18:02:04Z")

</div>

```auto
{
"_msgid" : 56fc02d6.3693bc,
"topic" : ,
"payload" : -{
"domain" : image_processing,
"service" : scan,
"data" : -{
"entity_id" : image_processing.facebox_office_camera
}
},
"data.attributes.matched_faces()" : 1,
"data" : -{
"entity_id" : image_processing.facebox_office_camera,
"state" : 1,
"attributes" : -{
"faces" : -[
-{
"name" : josiah,
"image_id" : IMG_4891.jpg,
"confidence" : 56.41,
"matched" : true,
"bounding_box" : -{
"top" : 270,
"left" : 906,
"width" : 155,
"height" : 155
},
"entity_id" : image_processing.facebox_office_camera
}
],
"total_faces" : 1,
"matched_faces" : -{
"josiah" : 56.41
},
"total_matched_faces" : 1,
"hostname" : hub,
"friendly_name" : facebox office_camera,
"device_class" : face
},
"last_changed" : 2019-10-05T17:41:09.476352+00:00,
"last_updated" : 2019-10-05T17:42:12.377173+00:00,
"context" : -{
"id" : 158c9b818cd84df8a2ad5826e4b2ca4c,
"parent_id" : ,
"user_id" : d29765725df941a590824c9df8541647
},
"timeSinceChangedMs" : 62914
}
}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 October 2019 18:10 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/4 "2019-10-05T18:10:08Z")

</div>

Looking at the example msg you posted, the name of the property has parentheses on the end

i.e. not a valid dot notation variable name so...

To access that in pure js you would need to use `object['name-of property ()']` to access it.

Hopefully that gives you a clue

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 October 2019 18:14 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/5 "2019-10-05T18:14:31Z")

</div>

I'm feeling generous....

in a function node, try this...

```auto
var mf = msg["data.attributes.matched_faces()"]
msg.payload = mf;
return msg;

```

Attach a debug node BEFORE and AFTER the function node - see what comes through in payload.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [5 October 2019 18:24 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/6 "2019-10-05T18:24:53Z")

</div>

Yes, but if you would like to match for the name as visible in the flow, the path would be `msg.data.attributes.faces`, which is an array of objects. A JSONata check to see if there’s an object in there matching with name “josiah” would likely be easiest.

---

<div class="post-metadata">

**Author:** ![subjectbit](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/subjectbit/32/12855_2.png) [@subjectbit](https://discourse.nodered.org/u/subjectbit)\
**Post date:** [5 October 2019 18:55 UTC](https://discourse.nodered.org/t/help-trying-to-extract-object-attribute/16357/7 "2019-10-05T18:55:15Z")

</div>

Ah-ha, I think this was what I was missing... I ended up using a split node with _data.attributes.matched\_faces. **name** _ where the name was the trained face and one for empty (i.e. unrecognized or no faces detected). I prefer to use the matched\_faces attribute over the faces attribute to account for an empty/unrecognized entity.

Thanks for your help and Steve-Mcl for your suggestion as well!
