# `JSONSchex.Validator`
[🔗](https://github.com/xinz/jsonschex/blob/main/lib/jsonschex/validator.ex#L1)

Executes compiled `Schema` rules against data, accumulating errors and tracking
evaluated keys for `unevaluatedProperties`/`unevaluatedItems`.

During validation, a context tuple is threaded through each rule:

    {path, evaluated_keys, validation_context}

- `path` — Reversed list of JSON Pointer segments (e.g., `["email", 0, "users"]`)
- `evaluated_keys` — `MapSet` of property names or array indices validated so far
- `validation_context` — `ValidationContext` struct referencing the root schema

## Examples

    iex> {:ok, schema} = JSONSchex.compile(%{"type" => "object", "properties" => %{"name" => %{"type" => "string"}}})
    iex> JSONSchex.Validator.validate(schema, %{"name" => "Alice"})
    :ok

# `validate`

```elixir
@spec validate(JSONSchex.Types.Schema.t(), term()) ::
  :ok | {:error, [JSONSchex.Types.Error.t()]}
```

Validates data against a compiled schema.

## Examples

    iex> {:ok, schema} = JSONSchex.compile(%{"type" => "integer", "minimum" => 0})
    iex> JSONSchex.Validator.validate(schema, 10)
    :ok

    iex> {:ok, schema} = JSONSchex.compile(%{"type" => "integer", "minimum" => 0})
    iex> {:error, errors} = JSONSchex.Validator.validate(schema, -5)
    iex> Enum.any?(errors, fn e -> e.rule == :minimum end)
    true

# `validate_entry`

```elixir
@spec validate_entry(
  JSONSchex.Types.Schema.t(),
  term(),
  list(),
  JSONSchex.Types.ValidationContext.t(),
  term()
) :: {:ok, MapSet.t()} | {:error, [JSONSchex.Types.Error.t()] | String.t()}
```

Recursive validation engine called by the rule dispatcher.

Executes all rules in the schema sequentially, accumulating errors and evaluated keys.

## Examples

    iex> {:ok, schema} = JSONSchex.compile(%{"type" => "string"})
    iex> ctx = %JSONSchex.Types.ValidationContext{root_schema: schema, scope_stack: [], source_id: nil, raw: nil}
    iex> JSONSchex.Validator.validate_entry(schema, "hello", [], ctx)
    {:ok, MapSet.new()}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
