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
""" | |
Building a Python object from JSON isn't as straightforward as it looks. | |
SimpleNamespace only allows you to access fields that are valid variable | |
names. This poses a problem for JSON that contains invalid characters. | |
Here is my solution: | |
``` | |
# Doesn't work: | |
>>> data = json.loads(some_str, object_hook=lambda d: SimpleNamespace(**d)) |