[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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
program | Program | - |
value | Value | - |
type | Type | - |
encodeAs? | EncodeData | Encoding override; otherwise uses applicable property or scalar encoding metadata. |
handlers? | ValueJsonSerializers | Optional custom scalar serializer. |
diagnosticTarget? | | DiagnosticTarget | typeof NoTarget | - |
Returns
Section titled “Returns”unknown
Throws
Section titled “Throws”If a function value cannot be serialized.
Throws
Section titled “Throws”If a recognized scalar uses an unsupported constructor.