strata_protocol/dynamic_json
Convert gleam/dynamic.Dynamic values back into gleam/json.Json so
frames decoded into the typed sum types (which carry payloads as
Dynamic) can be re-encoded to bytes for round-trip and proxying.
This is a deliberately public part of strata_protocol's API (not
internal/): both strata_server and strata_client need to turn a
decoded frame's Dynamic payload back into Json, and this module is
the single, shared place that does it — neither package should
reimplement the walk below.
Mirrors the pattern in beryl/wire. Handles strings, ints, floats,
bools, nil, lists, and string-keyed dicts. Falls back to json.null()
for anything else (e.g., tuples, atoms) — the protocol contract is JSON
values only.
Functions
Section titled “Functions”dynamic_to_json
Section titled “dynamic_to_json”Convert a Dynamic (decoded from JSON) back into json.Json.
Total, not partial: every input produces a Json value, falling back
to json.null() for shapes that cannot occur in JSON (tuples, atoms,
records). That fallback is only safe because every Dynamic this
function is called on originates from json.parse/decode.dynamic
somewhere upstream (a server or client frame decoder) — callers must
not feed it Dynamic built from arbitrary in-memory data.
pub fn dynamic_to_json(dynamic.Dynamic) -> json.Json