jsonschema validates JavaScript values against JSON Schema documents through draft-07. It returns structured errors, supports custom formats, and offers many validation options.
Overview
jsonschema is a JavaScript JSON Schema validator focused on speed and a small API surface. It fully supports schema versions through draft-07 and can validate plain objects, arrays, and nested structures against schemas you provide at runtime.
Validation returns a result object with validity, the instance, the schema used, and an array of errors listing paths, messages, failed keywords, and arguments. Options let you throw on first or all errors, treat undefined properties as invalid when required, disable format checking, or surface nested errors from oneOf and anyOf branches for easier debugging.
The validator implements standard keywords and types, custom attribute hooks, user-defined formats on instances or prototypes, schema dereferencing for remote definitions, rewrite hooks to coerce instances after successful validation, pre-property hooks, skipping or forbidding unknown keywords, and configurable base URIs for relative schema IDs.
Install paths documented include npm, yarn, and bun. The test suite draws on the shared JSON Schema test suite plus project-specific cases. Phone number formats follow the E.123 standard when format validation is enabled.
Key features
- JSON Schema draft-07 support
- Structured ValidatorResult errors
- Custom format validators
- Custom schema keyword attributes
- Remote schema dereferencing
- Optional throw on validation failure
- Instance rewrite after validation
- Configurable format validation disable
Use cases
- Request body validation in Node apps
- Config file sanity checks
- API contract testing in JavaScript
- Form payload validation on servers
- Extending schemas with custom keywords