jcrist · GitHub

Conversation

Closed

JSON as a protocol only supports string keys in objects, which means
that arbitrary key types can't be used. Previously we only allowed `str`
and `Literal[strings...]` types for dict keys. This commit relaxes this
restriction to support the following key types:
- `str`
- `Literal[strings...]`
- `Enum`
- `int`
- `Literal[integers...]`
- `IntEnum`
along with constraints on these types.
Integer keys are encoded/decoded as integer strings (e.g. `1 -> "1"`).

@jcrist

@jcrist

@jcrist

jcrist deleted the json-dict-int-keys branch

December 17, 2022 19:29

@Siyet Siyet mentioned this pull request

Jul 13, 2026

Open

Labels

None yet

Read the original on github.com ↗