PHPackages                             vrijdag/jsonvalidator - 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. vrijdag/jsonvalidator

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

vrijdag/jsonvalidator
=====================

JSON Validator

0.1(7y ago)03PHP &gt;=7.2

Since Feb 22Compare

[ Source](https://github.com/vrijdag/jsonvalidator)[ Packagist](https://packagist.org/packages/vrijdag/jsonvalidator)[ RSS](/packages/vrijdag-jsonvalidator/feed)WikiDiscussions Synced 3d ago

READMEChangelogDependenciesVersions (3)Used By (0)

Use using composer:

```
composer require dewebontw/jsonvalidator ^0.1

```

Beware that this is currently more a proof of concept, as it does more or less basic JSON validation.

The why:
--------

[](#the-why)

When working with JSON API's it's a lot of hassle validating the response. Are you going to do it something like this?

```
$json = json_decode($response_body, true));

if (is_array($json)) {
	foreach ($json as $property) {
		$info_i_need = $property['sub']['item'] ?? null;

		if (is_string($info_i_need)) {
			echo $info_i_need . "\n";
		}
	}
}
```

And this is only a really, really simple example. Usually it is loop in loop in loop.

JSON Schema
-----------

[](#json-schema)

Then there is [JSON Schema](https://json-schema.org/), which is great, but:

- It is in draft;
- The schema's can become quite large;
- All fields have to be defined, which does make sense, except:
    - When you only need 1% of the response the schema becomes quite unclear;
    - When the response changes (a field is added for example), the schema as a whole does not match anymore.

JSON Validator
--------------

[](#json-validator)

So I started working on this little JSON validator. Lets take this Yahoo weather as a example request:

In this response we can find all sorts of data, let's say I need the following:

- The language of the response;
- The current wind direction;
- The max high temperature of today's forecast.

Based on the response I have to create this 'schema'. Only the fields in this schema are required to be in the response, all other data is left alone.

```
{
  "query": {
    "lang": "string",
    "results": {
      "channel": {
        "wind": {
          "direction": "number"
        },
        "item": {
          "forecast": [
            {
              "high": "number"
            }
          ]
        }
      }
    }
  }
}
```

That's quite a clear file:

- The `query` property has to be an object, containing;
- A `language` property which needs to be a string;
- A `results` property, containing an object;
- Which contains a channel property

... and so on.

A special one is the `forecast` property. Based on the schema, this should contain an array of which each entry should be an object containing a `high` property which should be a number (that is a numeric string, not an int or float).

#### Tying this together

[](#tying-this-together)

So tying to this together we have a JSON response from the API and a schema, it would be something like this to validate:

```
$schema = file_get_contents('schema.json');
$response = file_get_contents('response.json');

try {
    $jsonValidator = new JsonValidator\JsonValidator($schema, $response);
    $jsonValidator->validate();

    // This now exists, and is numeric
    echo $jsonValidator->getData()->query->results->channel->wind->direction . "\n";

    foreach ($jsonValidator->getData()->query->results->channel->item->forecast as $forecast) {
        // Each days high temperature
        echo $forecast->high . "\n";
    }
}
catch (JsonValidator\Exceptions\JsonValidatorException $e) {
    echo $e->getMessage();
}
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2686d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc58fdd0684de8e79793e2f0c36ab08723ac3114fbbc4b5fc2375f0e7483ae6d?d=identicon)[vrijdag](/maintainers/vrijdag)

### Embed Badge

![Health badge](/badges/vrijdag-jsonvalidator/health.svg)

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

###  Alternatives

[chaoswey/taiwan-id-validator

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

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

PHPackages © 2026

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