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

JsonScalar

A JSON scalar -- string, number, boolean, or null.

JsonValue

An arbitrary JSON value modelled with ordinary mutable containers.

FrozenJsonValue

An immutable JSON value snapshot.

Functions

freeze_json(value)

Freeze a JSON-compatible value without retaining caller-owned containers.

thaw_json(value)

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 Mapping so a plain mutable dict satisfies it statically, while freeze_json() guarantees a MappingProxyType at 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 value is not JSON-compatible.

  • ValueError – If a floating-point value is non-finite.

Return type:

FrozenJsonValue

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:

JsonValue