PHPackages                             krydos/json-rules-checker - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. krydos/json-rules-checker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

krydos/json-rules-checker
=========================

A little library for checking JSON object via rules

124931PHP

Since Mar 24Pushed 11y ago4 watchersCompare

[ Source](https://github.com/KryDos/JSONRulesChecker)[ Packagist](https://packagist.org/packages/krydos/json-rules-checker)[ RSS](/packages/krydos-json-rules-checker/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (1)

[![Build Status](https://camo.githubusercontent.com/334eaa580179263f2ae9009f9d97d888eef5c65144eb166f1a88812e8b209b9d/68747470733a2f2f7472617669732d63692e6f72672f4b7279446f732f4a534f4e52756c6573436865636b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/KryDos/JSONRulesChecker)JSONRulesChecker
====================================================================================================================================================================================================================================================================================================================

[](#jsonruleschecker)

This is small library for validation JSON objects in PHP (via regex). You can describe required attributes and check it on requred values.

INSTALLATION
------------

[](#installation)

Please update your composer.json. Add this to your **require** section

```
"krydos/json-rules-checker":"dev-master"

```

WHY DO I NEED THIS
------------------

[](#why-do-i-need-this)

Very often I have a code like this:

```
try {
    $json = json_decode(getJsonStringFromAnyPlace());

    if(isset($json->attr1)) {
        // do something with $json->attr1

        if(isset($json->attr2)) {
            //do something with $json->attr2
        }
        else {
            throw new Exception('attr2 required');
        }
    }
    else {
        throw new Exception('attr1 required');
    }
}
catch(Exception $e) {
    // do something
}
```

I really don't like it. I wrote this library because I want to validate JSON using some rules.

Like that:

```
try {
    $json = json_decode(getJsonStringFromAnyPlace());
    // let's imagine that JSON looks something like this:
    // {"root":{"attr1":"value1", "attr2":"value2", "attr3":{"attr3_1":"123"}}}

    // let's write a rules
    $rules = array(
        'root' => array(
            'attr1' => '/^value1$/',
            'attr2' => '', // if you don't care what value has this attribute
                           // then just use empty string
            'attr3' => array(
                'attr3_1'=>'/^\d+$/' // just use regex for value validating
            )
        )
    );

    $validation_result = \JSONRulesChecker\JSONChecker::checkJSON($json, $rules); // return true
    if(!$validation_result) {
        throw new Excpetion('Please check you params');
    }
}
catch(Exception $e) {
    //do something
}
```

I like it :)

So, how to use it
-----------------

[](#so-how-to-use-it)

- create a JSON object via json\_decode() or other functions
- describe rules for your JSON object (just a PHP array as you can see above)
- call the rules checker and pass your JSON object and rules into checker like that:

```
\JSONRulesChecker\JSONChecker::checkJSON($json, $rules);
```

- by default checker expects that you described only required attributes in the rules array. This means that matching are not strict. For example if you JSON object has 3 keys but your rules array has only 2 (which matches with JSON) then checker will return **true**. So if you want to use **STRICT matching** then you can pass **true** as third parameter into checkJSON() function like this:

```
\JSONRulesChecker\JSONChecker::checkJSON($json, $rules, true);
```

Thanks
------

[](#thanks)

[@Sbrilenko](https://github.com/Sbrilenko) - for regex idea

Please feel free to Pull Requests

&lt;3

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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/6a6ad8ce7c088b44c2db13656f41bb1c93b5116b01c6ff942f8ee71d4112e590?d=identicon)[KryDos](/maintainers/KryDos)

---

Top Contributors

[![krydos](https://avatars.githubusercontent.com/u/910691?v=4)](https://github.com/krydos "krydos (32 commits)")[![Jleagle](https://avatars.githubusercontent.com/u/381099?v=4)](https://github.com/Jleagle "Jleagle (2 commits)")

### Embed Badge

![Health badge](/badges/krydos-json-rules-checker/health.svg)

```
[![Health](https://phpackages.com/badges/krydos-json-rules-checker/health.svg)](https://phpackages.com/packages/krydos-json-rules-checker)
```

###  Alternatives

[tinymighty/wiki-seo

A simple MediaWiki extension to give you control over the HTML title and meta tags via a tag or parser function.

174.2k](/packages/tinymighty-wiki-seo)

PHPackages © 2026

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