Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > JsonSchema

JsonSchema class

Represents a JSON schema that can be used to validate JSON data files loaded by the JsonFile class.

Signature:

export declare class JsonSchema 

Remarks

The schema itself is normally loaded and compiled later, only if it is actually required to validate an input. To avoid schema errors at runtime, it's recommended to create a unit test that calls JsonSchema.ensureCompiled() for each of your schema objects.

Properties

PropertyModifiersTypeDescription
shortNamereadonlystringReturns a short name for this schema, for use in error messages.

Methods

MethodModifiersDescription
ensureCompiled()If not already done, this loads the schema from disk and compiles it.
fromFile(filename, options)staticRegisters a JsonSchema that will be loaded from a file on disk.
fromLoadedObject(schemaObject)staticRegisters a JsonSchema that will be loaded from a file on disk.
validateObject(jsonObject, filenameForErrors, options)Validates the specified JSON object against this JSON schema. If the validation fails, an exception will be thrown.
validateObjectWithCallback(jsonObject, errorCallback)Validates the specified JSON object against this JSON schema. If the validation fails, a callback is called for each validation error.