Help trying to extract object attribute

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

The specific object value I'm trying to base the switch node off of is data.attributes.matched_faces

Any suggestions?

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

"_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

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

I'm feeling generous....

in a function node, try this...

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.

Yes, but if you would like to match for the name as visible in the flow, the path would be, 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.

Ah-ha, I think this was what I was missing... I ended up using a split node with 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!