JsonSchemaValidator class final

A compiled JSON Schema validator that validates Dart maps against a schema.

JsonSchemaValidator is a convenience wrapper around SchemaParser that accepts either a Map<String, dynamic> or a JSON string, compiles the schema at construction time, and exposes a single validate call.

This type is intended for consumers who need to validate documents against a JSON Schema without understanding the internal SchemaRule hierarchy.

Example:

final validator = JsonSchemaValidator.fromMap({
  'required': ['name', 'email'],
  'properties': {
    'name': {'type': 'string', 'minLength': 1},
    'email': {'type': 'string', 'format': 'email'},
  },
});

final violations = validator.validate({'name': 'Alice'});
// → [SchemaViolation(path: 'email', message: 'required field is missing')]

Constructors

JsonSchemaValidator.fromJson(String json)
Parses json as a JSON Schema string and compiles it into a validator.
factory
JsonSchemaValidator.fromMap(Map<String, dynamic> schema)
Compiles schema into a validator.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(Map<String, dynamic> document) List<SchemaViolation>
Validates document against the compiled schema.

Operators

operator ==(Object other) bool
The equality operator.
inherited