httk.serve.jsondata¶
Protocol-neutral JSON value model shared across httk serving protocols.
This module owns the recursive JSON data model used by every protocol
implementation in httk.serve, together with the deep freeze/thaw pair
that converts between ordinary caller-owned JSON containers and an immutable
snapshot representation.
httk.serve.http.JsonDocument is a deliberately laxer alias
(Mapping[str, object]) for a single JSON object accepted by the GET-app
factories, whereas JsonValue here models an arbitrary JSON value
recursively. The two are intentionally distinct and neither is defined in
terms of the other.
Attributes¶
A JSON scalar -- string, number, boolean, or null. |
|
An arbitrary JSON value modelled with ordinary mutable containers. |
|
An immutable JSON value snapshot. |
Functions¶
|
Freeze a JSON-compatible value without retaining caller-owned containers. |
|
Return an independent ordinary JSON value from an immutable snapshot. |
Module Contents¶
- type httk.serve.jsondata.JsonScalar = str | int | float | bool | None[source]¶
A JSON scalar – string, number, boolean, or null.
- type httk.serve.jsondata.JsonValue = JsonScalar | list['JsonValue'] | dict[str, 'JsonValue'][source]¶
An arbitrary JSON value modelled with ordinary mutable containers.
- type httk.serve.jsondata.FrozenJsonValue = JsonScalar | tuple['FrozenJsonValue', ...] | Mapping[str, 'FrozenJsonValue'][source]¶
An immutable JSON value snapshot.
The mapping arm is typed as
Mappingso a plain mutabledictsatisfies it statically, whilefreeze_json()guarantees aMappingProxyTypeat runtime. This static/runtime gap is intentional and is not closed here.
- httk.serve.jsondata.freeze_json(value)[source]¶
Freeze a JSON-compatible value without retaining caller-owned containers.
- Parameters:
value (object) – JSON-compatible value to copy into an immutable representation.
- Returns:
An immutable JSON-compatible value.
- Raises:
TypeError – If
valueis not JSON-compatible.ValueError – If a floating-point value is non-finite.
- Return type:
- httk.serve.jsondata.thaw_json(value)[source]¶
Return an independent ordinary JSON value from an immutable snapshot.
- Parameters:
value (FrozenJsonValue) – Immutable JSON-compatible value to copy.
- Returns:
Plain JSON-compatible lists and dictionaries.
- Return type: