Skip to content

[F] serializeValueAsJson

function serializeValueAsJson(
program,
value,
type,
encodeAs?,
handlers?,
diagnosticTarget?
): unknown;

Serialize the given TypeSpec value as a JSON object using the given type and its encoding annotations. The Value MUST be assignable to the given type. Returns a JavaScript value, not JSON text. Object properties and enum values honor JSON encoded names. Custom scalar values with no recognized standard base serialize to undefined unless a handler overrides them.

ParameterTypeDescription
programProgram-
valueValue-
typeType-
encodeAs?EncodeDataEncoding override; otherwise uses applicable property or scalar encoding metadata.
handlers?ValueJsonSerializersOptional custom scalar serializer.
diagnosticTarget?| DiagnosticTarget | typeof NoTarget-

unknown

If a function value cannot be serialized.

If a recognized scalar uses an unsupported constructor.