A microlibrary that defines a Json type alias for Python.
Seriously, this is all the code:
from typing import Dict, List, Union
Json = Union[Dict[str, "Json"], List["Json"], str, int, float, bool, None]If we only supported Python >= 3.10, it would fit on one line:
Json = dict[str, 'Json'] | list['Json'] | str | int | float | bool | NoneI want to use this type alias in multiple projects and it's just about long enough to be annoying.
This alias should probably get added to the Python typing module.
If it does and I haven't put a big notice on this README,
please open a PR.
from jsonalias import Json
d: Json = {"foo": ["bar", {"x": "y"}]}Make sure you're using mypy >= 0.981 and running with the
--enable-recursive-aliases flag.
GitHub user wbolster for this comment notifying us that mypy could now do JSON.