I like python single liner:
u = payload.get("actor", {}).get("username", "")
The problem I am facing is that I can’t control what the “payload” is, other than knowing this vocabulary. So, if the "payload" does not have an "actor", or it does, and the actor has or does not have a "username", this single-line font is fine.
The problem, of course, arises when the payload has an actor, but the actor is not a dictionary.
Is there a way to do this comprehensively, as one liner, and consider the possibility that the "actor" may not be a dictionary?
Of course, I can check the type using "isinstance", but it's not so nice.
I don’t need one liner per se, just asking for the most effective way to ensure that “u” is populated without exception and without prior knowledge of what exactly is in the “payload”.
source
share