mcp.protocol.jsonhelpers

Internal typed helpers for reading optional fields out of a vibe.data.json.Json object. They centralize the "is the key present AND of the expected type" guard that every fromJson body would otherwise hand-roll, giving one place to audit how malformed wire input is handled.

Members

Functions

getOr
T getOr(Json j, string key, T fallback)

Read j[key] as T, returning fallback when the key is absent, present with a mismatched JSON type, or (for narrow integral T) when the wire value is outside T's range. Never throws, so it is safe for tolerant wire parsing.

tryGet
bool tryGet(Json j, string key, T val)

Assign j[key] into val only when the key is present, its JSON type matches T, and (for narrow integral T) the wire value fits in T's range. Leaves val untouched otherwise (preserving any default). Returns whether the assignment happened. Never throws.

tryGet
bool tryGet(Json j, string key, N val)

Nullable overload: assigns the unwrapped value into val (leaving it untouched — preserving any pre-set default — on a missing/mismatched field), so a struct's Nullable!T field can be filled directly without a temporary.