typelets.json

Typing useful for working with JSON structures.

Added in version 1.0.

Module Attributes

JSONValue

A type indicating a valid value in JSON data.

JSONDict

A type for a dictionary mapping strings to JSON values.

JSONDictImmutable

An immutable type mapping strings to JSON values.

JSONList

A type for a list of JSON values.

JSONListImmutable

An immutable type of a list of JSON values.

BaseSerializableJSONValue

Base type indicating a valid value that can be serialized to JSON.

BaseSerializableJSONDict

Base type for a dictionary mapping strings to JSON-serializable values.

BaseSerializableJSONDictImmutable

Base type for an immutable mapping of strings to JSON-serializable values.

BaseSerializableJSONList

Base type for a list of JSON-serializable values.

BaseSerializableJSONListImmutable

Base type for an immutable sequence of JSON-serializable values.

typelets.json.JSONValue

A type indicating a valid value in JSON data.

All values are natively-supported JSON data. Custom serializers that support more data types will need to add their own special type.

Added in version 1.0.

alias of JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str

typelets.json.JSONDict

A type for a dictionary mapping strings to JSON values.

All values are natively-supported JSON data.

All values are natively-supported JSON data. Custom serializers that support more data types will need to add their own special type.

Added in version 1.0.

alias of Dict[str, JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str]

typelets.json.JSONDictImmutable

An immutable type mapping strings to JSON values.

This is an immutable version of JSONDict, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.

All values are natively-supported JSON data. Custom serializers that support more data types will need to add their own special type.

Added in version 1.0.

alias of Mapping[str, JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str]

typelets.json.JSONList

A type for a list of JSON values.

All values are natively-supported JSON data. Custom serializers that support more data types will need to add their own special type.

Added in version 1.0.

alias of List[JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str]

typelets.json.JSONListImmutable

An immutable type of a list of JSON values.

This is an immutable version of JSONList, which cannot be modified once set. It can help with type narrowing and is recommended when returning data from a function that should not be changed.

All values are natively-supported JSON data. Custom serializers that support more data types will need to add their own special type.

Added in version 1.0.

alias of Sequence[JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str]

typelets.json.BaseSerializableJSONValue

Base type indicating a valid value that can be serialized to JSON.

Consumers can create a type alias for this that provides a set of additional types that can be serialized to JSON.

Added in version 1.0.

Example

SerializableJSONValue: TypeAlias = \
    BaseSerializableJSONValue[Union[datetime, UUID]]

alias of BaseSerializableJSONDict[_T] | BaseSerializableJSONList[_T] | BaseSerializableJSONDictImmutable[_T] | BaseSerializableJSONListImmutable[_T] | JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str | _T

typelets.json.BaseSerializableJSONDict

Base type for a dictionary mapping strings to JSON-serializable values.

Consumers can create a type alias for this that provides a set of additional types that can be serialized to JSON.

Added in version 1.0.

Example

SerializableJSONDict: TypeAlias = \
    BaseSerializableJSONDict[Union[datetime, UUID]]

alias of Dict[str, BaseSerializableJSONDict[_T] | BaseSerializableJSONList[_T] | BaseSerializableJSONDictImmutable[_T] | BaseSerializableJSONListImmutable[_T] | JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str | _T]

typelets.json.BaseSerializableJSONDictImmutable

Base type for an immutable mapping of strings to JSON-serializable values.

Consumers can create a type alias for this that provides a set of additional types that can be serialized to JSON.

Added in version 1.0.

Example

SerializableJSONDictImmutable: TypeAlias = \
    BaseSerializableJSONDictImmutable[Union[datetime, UUID]]

alias of Mapping[str, BaseSerializableJSONDict[_T] | BaseSerializableJSONList[_T] | BaseSerializableJSONDictImmutable[_T] | BaseSerializableJSONListImmutable[_T] | JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str | _T]

typelets.json.BaseSerializableJSONList

Base type for a list of JSON-serializable values.

Consumers can create a type alias for this that provides a set of additional types that can be serialized to JSON.

Added in version 1.0.

Example

SerializableJSONList: TypeAlias = \
    BaseSerializableJSONList[Union[datetime, UUID]]

alias of List[BaseSerializableJSONDict[_T] | BaseSerializableJSONList[_T] | BaseSerializableJSONDictImmutable[_T] | BaseSerializableJSONListImmutable[_T] | JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str | _T]

typelets.json.BaseSerializableJSONListImmutable

Base type for an immutable sequence of JSON-serializable values.

Consumers can create a type alias for this that provides a set of additional types that can be serialized to JSON.

Added in version 1.0.

Example

SerializableJSONListImmutable: TypeAlias = \
    BaseSerializableJSONListImmutable[Union[datetime, UUID]]

alias of Sequence[BaseSerializableJSONDict[_T] | BaseSerializableJSONList[_T] | BaseSerializableJSONDictImmutable[_T] | BaseSerializableJSONListImmutable[_T] | JSONDict | JSONDictImmutable | JSONList | JSONListImmutable | None | bool | float | int | str | _T]