Created
November 26, 2017 11:55
-
-
Save nderkach/58c3ad7a27616265d081a1976d78e99d to your computer and use it in GitHub Desktop.
How to convert JSON data into a Python object
This file contains hidden or 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
# stolen from https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object/15882054#15882054 | |
def _json_object_hook(d): | |
return namedtuple('X', d.keys())(*d.values()) | |
def json2obj(data): | |
return json.loads(data, object_hook=_json_object_hook) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment