JSON Serialization
Learn about the JSON object serialization in Python.
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 ...