https://github.com/kevinheavey/jsonalias
A microlibrary that defines a Json type alias for Python
https://github.com/kevinheavey/jsonalias
Last synced: 23 days ago
JSON representation
A microlibrary that defines a Json type alias for Python
- Host: GitHub
- URL: https://github.com/kevinheavey/jsonalias
- Owner: kevinheavey
- License: mit
- Created: 2022-10-28T21:58:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-14T14:42:34.000Z (4 months ago)
- Last Synced: 2025-04-09T22:18:34.929Z (23 days ago)
- Language: Python
- Size: 10.7 KB
- Stars: 19
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonalias
A microlibrary that defines a `Json` type alias for Python.
## This README is longer than the library
Seriously, this is all the code:
```python
from typing import Dict, List, UnionJson = Union[Dict[str, "Json"], List["Json"], str, int, float, bool, None]
```If we only supported Python >= 3.10, it would fit on one line:
```python
Json = dict[str, 'Json'] | list['Json'] | str | int | float | bool | None
```## Then why make a library out of it?
I 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.## Example
```python
from jsonalias import Jsond: Json = {"foo": ["bar", {"x": "y"}]}
```## It's not working please help???
Make sure you're using mypy >= 0.981 and running with the
`--enable-recursive-aliases` flag.## Special Thanks
GitHub user wbolster for [this comment](https://github.com/python/typing/issues/182#issuecomment-1259412066)
notifying us that mypy could now do JSON.