PHPackages                             riley19280/fluent-json-schema - 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. riley19280/fluent-json-schema

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

riley19280/fluent-json-schema
=============================

Create json schemas with ease

v1.2.1(1y ago)22431[5 PRs](https://github.com/Riley19280/fluent-json-schema/pulls)1MITPHPCI passing

Since Oct 17Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/Riley19280/fluent-json-schema)[ Packagist](https://packagist.org/packages/riley19280/fluent-json-schema)[ RSS](/packages/riley19280-fluent-json-schema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (13)Versions (11)Used By (1)

fluent-json-schema
==================

[](#fluent-json-schema)

Create json schema with ease

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

[](#installation)

```
composer require riley19280/fluent-json-schema

```

Basic Usage
-----------

[](#basic-usage)

```
use FluentJsonSchema\FluentSchema;

$schema = FluentSchema::make()
    ->type()->object()
    ->property('name', FluentSchema::make()
        ->type()->string()
    )
    ->return()
    ->compile();
/* Results in
{
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        }
    }
}
*/
```

More advanced usage can be found [here](https://github.com/Riley19280/fluent-json-schema/blob/master/tests/Unit/EndToEndTest.php). The entire meta-schema spec has been implemented using this package.

### Contexts

[](#contexts)

There are several different "contexts" that you can be in while constructing json schema objects. These are the main data type contexts

- array
- integer
- number
- object
- string

Each of them have different methods that set specific properties related to that data type. If at any time you need to return to the "global" context, you can call the `return` method.

### Boolean Schemas

[](#boolean-schemas)

In some cases, a schema that evaluates to `true` or `false` is needed, you can pass `FluentSchema::make()->true()` or `FluentSchema::make()->false()`

```
FluentSchema::make()
    ->type()->object()
    ->additionalProperties(FluentSchema::make()->false())
```

### Converting to JSON

[](#converting-to-json)

When done constructing your schema object, call the `compile` method on it. This will return a php array that you can then serialize to json.

By default, properties will be serialized in the order they are added to an object, i.e.

```
$schema = FluentSchema::make()->schema('schema')->id('id')->compile();
// Will be
// { "$schema": "schema", "$id": "id" }
$schema = FluentSchema::make()->id('id')->schema('schema')->compile();
// Will be
// { "$id": "id", "$schema": "schema" }
```

This can be changed by calling `$schema->getSchemaDTO()->setKeyOrder(['$id', '$schema'])`. This will override the serialization order. Any unlisted keys will be added to the end.

Validation
----------

[](#validation)

Validation is done using the [justinrainbow/json-schema](https://github.com/justinrainbow/json-schema) package.

The following methods are available on the `FluentSchema` object to aid in schema validation:

- `getSchemaStorage(): SchemaStorage`
- `setSchemaStorage(SchemaStorage $schemaStorage): static`
- `validate(mixed &$data, int $checkMode = null): Validator`
- `addValidationSchema(object|array $schema, string $id = null): static`

```
$isValid = FluentSchema::make()
    ->type()->object()
    ->property('name', FluentSchema::make()
        ->type()->string()
    )
    ->return()
    ->validate((object)[
        'name' => 'validated!',
    ])
    ->isValid();
```

Please see the package documentation [justinrainbow/json-schema](https://github.com/justinrainbow/json-schema) for more detailed information on validation.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance52

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% 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 ~79 days

Total

5

Last Release

620d ago

### Community

Maintainers

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

---

Top Contributors

[![Riley19280](https://avatars.githubusercontent.com/u/14127031?v=4)](https://github.com/Riley19280 "Riley19280 (21 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (15 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/riley19280-fluent-json-schema/health.svg)

```
[![Health](https://phpackages.com/badges/riley19280-fluent-json-schema/health.svg)](https://phpackages.com/packages/riley19280-fluent-json-schema)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[illuminate/support

The Illuminate Support package.

583107.1M34.4k](/packages/illuminate-support)[illuminate/collections

The Illuminate Collections package.

27171.5M820](/packages/illuminate-collections)[ergebnis/composer-normalize

Provides a composer plugin for normalizing composer.json.

1.1k37.3M2.1k](/packages/ergebnis-composer-normalize)[illuminate/events

The Illuminate Events package.

13454.3M1.7k](/packages/illuminate-events)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M210](/packages/illuminate-pipeline)

PHPackages © 2026

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