JSON Serialization
Explore JSON serialization in Python, focusing on serializing common object types like dictionaries and lists, managing nested data, and efficiently processing large datasets using newline-delimited JSON. Understand type hinting and the limitations of static type checking for JSON validation to effectively handle serialization tasks.
We'll cover the following...
The JSON format can serialize a number of commonly used Python object classes, including:
- None
- Boolean
- Float and integer
- String
- Lists of compatible objects
- Dictionaries with string keys and compatible objects as values
The compatible objects can include nested structures. This dictionary-within-list and dictionary-within-dictionary recursion can allow JSON to represent very complex things.
We might consider a theoretical (but invalid) type hint like the following:
JSON = Union[None, bool, int, float, str, List['JSON'], Dict[str, 'JSON']]
This hint isn’t directly supported by mypy, because it involves explicit recursion: the JSON type ...