June 2019
Beginner to intermediate
770 pages
19h 24m
English
In order to decode objects from a string in JSON notation, we need to work within the structure of a JSON parsing. Objects of our customized class definitions were encoded as simple dicts. This means that each dict decoded by the JSON decoder could be one of our customized classes. Or, what is serialized as a dict should be left as a dict.
The JSON decoder object hook is a function that's invoked for each dict to see whether it represents a customized object. If dict isn't recognized by the hook function, it's an ordinary dictionary and should be returned without modification. Here's our object hook function:
def blog_decode(some_dict: Dict[str, Any]) -> Dict[str, Any]: if set(some_dict.keys()) == {"__class__", ...
Read now
Unlock full access