Created
March 29, 2014 18:41
-
-
Save bencharb/9860373 to your computer and use it in GitHub Desktop.
dict to properties: foo.get('bar') to foo.bar (dict to object with dotted notation properties)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From Nery Jr on SO: http://stackoverflow.com/a/21502348 | |
# If you want to save lines of code and leave the most flexible solution, we can deserialize the json string to a dynamic object: | |
p = lambda:None | |
p.__dict__ = json.loads('{"action": "print", "method": "onData", "data": "Madan Mohan"}') | |
# >>>> p.action | |
# output: u'print' | |
# >>>> p.method | |
# output: u'onData' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment