Skip to content

Home > llm-ops > createJsonValidator

createJsonValidator() function

Returns a JSON validator for a given TypeScript schema. Validation is performed by an in-memory instance of the TypeScript compiler. The specified type argument T must be the same type as typeName in the given schema.

Signature:

typescript
export declare function createJsonValidator<T extends object = object>(schema: string, typeName: string): TypeChatJsonValidator<T>;
export declare function createJsonValidator<T extends object = object>(schema: string, typeName: string): TypeChatJsonValidator<T>;

Parameters

ParameterTypeDescription
schemastringA string containing the TypeScript source code for the JSON schema.
typeNamestringThe name of the JSON target type in the schema.

Returns:

TypeChatJsonValidator<T>

A TypeChatJsonValidator<T> instance.

Released under the MIT License.