PHPackages                             phindmarsh/statham - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. phindmarsh/statham

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

phindmarsh/statham
==================

A JSON Schema validator

v1.0.4(8mo ago)226.2k↓57.1%31MITPHPPHP ^8.1 || ^8.2 || ^8.3 || ^8.4CI passing

Since Feb 25Pushed 8mo ago2 watchersCompare

[ Source](https://github.com/phindmarsh/statham)[ Packagist](https://packagist.org/packages/phindmarsh/statham)[ RSS](/packages/phindmarsh-statham/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)Dependencies (1)Versions (8)Used By (1)

statham
=======

[](#statham)

A JSON Schema validator written in PHP

This is a (pretty much straight up) port of the Javascript [ZSchema](https://github.com/zaggino/z-schema) library for validating JSON against JSON schemas, and validating JSON Schemas themselves.

Why
---

[](#why)

Motivation for writing this was to validate [swagger.io](https://swagger.io) files in PHP, and none of the existing validators worked with recursive schemas, or resolved nested references properly. The Javascript one worked as I needed it to, so I ported it.

So Statham will:

- Not recurse infinitely when validating a schema that references itself
- Properly deal with $refs that are located in different schemas

Usage
-----

[](#usage)

```
// schemas used during validation
$schemas = [
  "http://json-schema.org/draft-04/schema#"
  "http://swagger.io/v2/schema.json#"
];

$statham = new \Statham\Statham();

// download each schema and add to internal cache
foreach($schemas as $schema_url){
    $schema = json_decode(file_get_contents($schema_url));
    $statham->setRemoteReference($schema_url, $schema);
}

// just validate the schema (no data)
$statham->validateSchema($schemas[1]);

// validate $json_to_validate against a given schema
$statham->validate($json_to_validate, $schemas[1]);
```

Statham doesn't automatically download externally referenced schemas, (it totally could, but reasons), so use `$statham->setRemoteReference($url, $schema_object)` for any schemas that will be used during validation.

Schemas can either be passed as an object (doesn't support schemas as arrays, but again, totally *could*), or if you've used `$statham->setRemoteReference()` you can pass it as a string, being the URL of the schema.

JSON data can only be passed as objects, so just use `json_decode($json)` (no second `true` argument) and you'll be fine.

Todo
----

[](#todo)

It doesn't check formats properly (so emails, dates, etc aren't validated they are anything beyond a string). This is easy enough to do, I just haven't yet.

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance61

Regular maintenance activity

Popularity33

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 58.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~970 days

Total

5

Last Release

243d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/344000?v=4)[Patrick Hindmarsh](/maintainers/phindmarsh)[@phindmarsh](https://github.com/phindmarsh)

---

Top Contributors

[![mattrenner](https://avatars.githubusercontent.com/u/1264226?v=4)](https://github.com/mattrenner "mattrenner (7 commits)")[![phindmarsh](https://avatars.githubusercontent.com/u/344000?v=4)](https://github.com/phindmarsh "phindmarsh (4 commits)")[![calcinai](https://avatars.githubusercontent.com/u/2415868?v=4)](https://github.com/calcinai "calcinai (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phindmarsh-statham/health.svg)

```
[![Health](https://phpackages.com/badges/phindmarsh-statham/health.svg)](https://phpackages.com/packages/phindmarsh-statham)
```

###  Alternatives

[ziming/laravel-zxcvbn

Zxcvbn Password validation rule for Laravel

3064.3k](/packages/ziming-laravel-zxcvbn)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
