What is best practice to determine if object has property (ideally at any depth)?

What is the best way to test this condition?

when: “{{object is defined and object.property is defined and object.property.property is defined and object.property.property == ‘mystring’}}”

A custom lookup?

What's best is always relative, but you could use this
when: ((object | default()).property | default()).property | default() == 'mystring'

And remember, don't use curly brackets in when.