PHPackages                             jermainedavy/json-validator - 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. jermainedavy/json-validator

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

jermainedavy/json-validator
===========================

A library to validate a json string against a model defined as a php class.

01

Since Oct 21Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JermaineDavy/json-validator)[ Packagist](https://packagist.org/packages/jermainedavy/json-validator)[ RSS](/packages/jermainedavy-json-validator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Json-Validator
==============

[](#json-validator)

Installation
------------

[](#installation)

To install this package use the following command:

```
composer install JermaineDavy\JsonValidator
```

If you don't have the Composer package manager installed, you could download it at this [link](https://getcomposer.org/download/)

Usage
-----

[](#usage)

This packages allows json strings to be evaluated against models represented by classes.

### Basic Usage

[](#basic-usage)

It's simple to use and only requires that 2 things be done.

1. Define a model
    - The model must be a child class of the Validator class.

```
use JermaineDavy\JsonValidator\Validator;

class Test extends Validator{
    public array $state = [
        "type" => "boolean",
        "required" => true
    ];

    public array $message = [
        "type" => "string",
        "min" => 3,
        "max" => 100
    ];
}
```

2. Run the json validation against the model.

```
$validator = new Test();

$response = $validator->validate($json);
```

The validate method returns an object containing only 2 properties. The `status` of the validation and a `message` explaining the status. If the status returned it `true` then the validation has been successful, otherwise the validation has failed and more information could be deemed from the message.

### What checks are allowed?

[](#what-checks-are-allowed)

- type(string)-&gt; Checks that the type specified in the JSON matches that of the type in the model
- required(boolean) -&gt; Checks that a field of the model is within the JSON
- min(double|integer) -&gt; Checks that the string length or number is less than what is specified in the model
- max(double|integer) -&gt; Checks that the string length or number is greater than what is specified in the model
- enum(array) -&gt; Checks that the JSON value matches one of the values in a given array
- regex(string|array) -&gt; Performs 1 or more checks to see if the value matches a regular expression
- dateFormat(string) -&gt; Checks that the JSON value matches a given date format
- custom(Closure) -&gt; Used for custom checks which might not be defined by this library. The closure should return an empty string is successful or an error string if it failed.

The type value could also refer to Other Models which extend the Validator class. Eg.

```
use JermaineDavy\JsonValidator\Validator;

class Test extends Validator{
    public array $state = [
        "type" => "boolean",
        "required" => true
    ];

    public array $object = [
        "type" => SecondTest::class
    ];
}
```

This syntax would work for both a single instance of `SecondTest` or an array of `SecondTest`

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/27dd014f3ca5201e397685af31c05d861dd566c5ec06dd0b15bf82b317bee3c2?d=identicon)[JermaineDavy](/maintainers/JermaineDavy)

---

Top Contributors

[![JermaineDavy](https://avatars.githubusercontent.com/u/39907947?v=4)](https://github.com/JermaineDavy "JermaineDavy (2 commits)")

### Embed Badge

![Health badge](/badges/jermainedavy-json-validator/health.svg)

```
[![Health](https://phpackages.com/badges/jermainedavy-json-validator/health.svg)](https://phpackages.com/packages/jermainedavy-json-validator)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

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