"when: key1.key2 is defined" not working

I’m trying to create a condition which checks if a dict has a certain subkey, e.g.:

when: key1.key2 is defined

The when condition is always true if key1 is defined, but it doesn’t check if key2 is also defined. How can such a condition be realized?

Already found out how…

`
when: key1 is defined and key1.key2 is defined

`

You should probably show your code, since this works and is used all the time.