Kaizen
Browse modulesPersistenceFunctions

Function: toJsonColumn()

function toJsonColumn<T>(value: T): InputJsonValue;

Defined in: server/persistence/json-column.ts:31

Hands a JSON-serializable domain value to a Prisma Json column.

Prisma's InputJsonValue is a recursive structural type that a normal domain interface never satisfies: any optional property widens to T | undefined, and undefined is not a member of InputJsonValue. So every write to a Json column needed an assertion, and the idiom that spread through the repositories was value as unknown as Prisma.InputJsonValue — 36 sites, each costing up to three lint warnings (two consistent-type-assertions, one no-unknown).

This is the one place that conversion happens. It is a real, unavoidable boundary — Prisma serializes with JSON.stringify, which drops undefined properties, so the value genuinely is JSON-safe at runtime even though the type system cannot express it. Naming the boundary once is better than repeating an unexplained double cast at every call site.

// before
data: input.data as unknown as Prisma.InputJsonValue,
// after
data: toJsonColumn(input.data),

Only for values that really are JSON-serializable. It will not save you from writing a Date, a Map, a BigInt, or a class instance — those survive the type check here and then serialize to something you did not intend.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

InputJsonValue

On this page