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
Property | Modifiers | Type | Description |
---|---|---|---|
shortName | readonly | string | Returns a short name for this schema, for use in error messages. |
Methods
Method | Modifiers | Description |
---|---|---|
ensureCompiled() | If not already done, this loads the schema from disk and compiles it. | |
fromFile(filename, options) | static | Registers a JsonSchema that will be loaded from a file on disk. |
fromLoadedObject(schemaObject) | static | Registers 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. |