PHPackages                             nadar/php-schemaorg-jsonld-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. nadar/php-schemaorg-jsonld-validator

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

nadar/php-schemaorg-jsonld-validator
====================================

A PHP library that validates JSON-LD structured data against the schema.org vocabulary.

1.0(2mo ago)0221↓50%MITPHPPHP &gt;=8.4CI passing

Since Feb 24Pushed 2mo agoCompare

[ Source](https://github.com/nadar/php-schemaorg-jsonld-validator)[ Packagist](https://packagist.org/packages/nadar/php-schemaorg-jsonld-validator)[ RSS](/packages/nadar-php-schemaorg-jsonld-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Schema.org JSON-LD Validator for PHP
====================================

[](#schemaorg-json-ld-validator-for-php)

[![Tests](https://github.com/nadar/php-schemaorg-jsonld-validator/actions/workflows/tests.yml/badge.svg)](https://github.com/nadar/php-schemaorg-jsonld-validator/actions/workflows/tests.yml)

A PHP 8.4+ library that validates JSON-LD structured data against the official [schema.org](https://schema.org) vocabulary — mirroring what [validator.schema.org](https://validator.schema.org/) checks for.

[![Schema Org JSON-LD Validator](schemaorgvalidator.png "Schema Org JSON-LD Validator")](schemaorgvalidator.png)

What it does
------------

[](#what-it-does)

The validator inspects a JSON-LD document (as a PHP array or raw JSON string) and reports:

1. **Unknown properties** — keys that are not part of the schema.org vocabulary.
2. **Wrong-domain properties** — properties used on a `@type` they do not belong to (the full `rdfs:subClassOf` type-inheritance hierarchy is respected, so subtype properties are always valid on parent types too).
3. **Unknown `@type` values** — type names that do not exist in the schema.org vocabulary.

The schema.org vocabulary ships **bundled** with this package as versioned JSON-LD definition files — no network access or caching required.

Requirements
------------

[](#requirements)

- PHP **8.4** or later
- The `json` extension (included in PHP by default)

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

[](#installation)

```
composer require nadar/php-schemaorg-jsonld-validator
```

Quick start
-----------

[](#quick-start)

```
use Nadar\Schema\JsonLdValidator;

$validator = new JsonLdValidator();

$jsonLd = [
    '@context' => 'https://schema.org',
    '@type'    => 'Course',
    'name'     => 'Introduction to PHP',
    'url'      => 'https://example.com/php-course',
];

$result = $validator->validate($jsonLd);

if ($result->isValid()) {
    echo 'Valid!';
} else {
    // Get errors as an array
    print_r($result->getErrors());

    // …or as a single string (default separator: newline)
    echo $result->getErrorsAsString();

    // Custom separator
    echo $result->getErrorsAsString(' | ');
}
```

You can also pass a raw JSON string instead of a decoded array:

```
$result = $validator->validate('{"@context":"https://schema.org","@type":"Course","name":"PHP 101"}');
```

Because each `validate()` call returns an independent `ValidationResult` object, you can validate multiple documents without any shared mutable state:

```
$resultA = $validator->validate($documentA);
$resultB = $validator->validate($documentB);

// $resultA and $resultB are completely independent.
```

Strict type checking
--------------------

[](#strict-type-checking)

The `$strictRequireType` parameter of `validate()` controls how the validator handles JSON-LD nodes that are missing a `@type` key.

### Default behaviour — `strictRequireType: false`

[](#default-behaviour--strictrequiretype-false)

By default, nodes without `@type` are **silently accepted**. Properties on such nodes are still checked against the list of known schema.org properties (unknown properties are still reported), but no domain check is performed because there is no type to check against.

```
$validator = new \Nadar\Schema\JsonLdValidator();

$result = $validator->validate([
    '@context' => 'https://schema.org',
    'name'     => 'No type declared',     // ✔ allowed — 'name' is a known property
    'fakeKey'  => 'value',                // ✗ reported — 'fakeKey' is not a schema.org property
]); // strictRequireType defaults to false
```

This permissive default is useful when you work with partial documents, embedded sub-graphs, or third-party data that does not always include explicit type declarations.

### Strict behaviour — `strictRequireType: true`

[](#strict-behaviour--strictrequiretype-true)

When strict mode is enabled, every node in the document **must** declare a `@type`. Any node that omits it produces an error like:

```
$: Missing @type.
$.provider: Missing @type.

```

Enable this mode when you want to guarantee that every entity is explicitly typed — a common requirement for rich-snippet and SEO structured data, where search engines rely on `@type` to understand what an entity represents.

```
$validator = new \Nadar\Schema\JsonLdValidator();

$result = $validator->validate([
    '@context' => 'https://schema.org',
    'name'     => 'Missing @type here',
], strictRequireType: true);

// $result->isValid() === false
// $result->getErrors() === ['$: Missing @type.']
```

With a proper `@type`, strict mode passes without issues:

```
$validator = new \Nadar\Schema\JsonLdValidator();

$result = $validator->validate([
    '@context' => 'https://schema.org',
    '@type'    => 'Course',
    'name'     => 'PHP 101',
], strictRequireType: true);

// $result->isValid() === true  (no errors)
```

Bundled vocabulary versions
---------------------------

[](#bundled-vocabulary-versions)

The vocabulary is bundled inside `src/vocabulary/` as dated JSON-LD files and exposed via the `Vocabulary` enum. Each case maps to one bundled file:

Enum caseFileschema.org version`Vocabulary::V20260226``src/vocabulary/2026-02-26.jsonld`v29.4To pin to a specific version explicitly:

```
use Nadar\Schema\Vocabulary;
use Nadar\Schema\JsonLdValidator;

$validator = new JsonLdValidator(vocabulary: Vocabulary::V20260226);
```

When a new schema.org release is bundled in a future version of this package, a new `Vocabulary` case will be added with an updated date. You can then choose when to adopt it by updating the `$vocabulary` argument.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance84

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Unknown

Total

1

Last Release

83d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86184bf08843ed8fcc4aedb2fdecd8a9e832e47e89a7166cebfda529c176f5ce?d=identicon)[nadar](/maintainers/nadar)

---

Top Contributors

[![nadar](https://avatars.githubusercontent.com/u/3417221?v=4)](https://github.com/nadar "nadar (8 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (6 commits)")

---

Tags

validatorJSON-LDjsonldseostructured-dataschema.org

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nadar-php-schemaorg-jsonld-validator/health.svg)

```
[![Health](https://phpackages.com/badges/nadar-php-schemaorg-jsonld-validator/health.svg)](https://phpackages.com/packages/nadar-php-schemaorg-jsonld-validator)
```

###  Alternatives

[composer/spdx-licenses

SPDX licenses list and validation library.

1.4k184.2M25](/packages/composer-spdx-licenses)[opis/json-schema

Json Schema Validator for PHP

64736.9M186](/packages/opis-json-schema)[laminas/laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria

15644.9M188](/packages/laminas-laminas-validator)[brotkrueml/schema

Embedding schema.org vocabulary - API and view helpers for schema.org markup

33584.6k13](/packages/brotkrueml-schema)[ergebnis/json-schema-validator

Provides a JSON schema validator, building on top of justinrainbow/json-schema.

3626.9M7](/packages/ergebnis-json-schema-validator)[brick/schema

Schema.org library for PHP

5163.7k1](/packages/brick-schema)

PHPackages © 2026

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