ricfr/json-structure

This Package validates Laravel Requests against the new JSON Structure Specification which provides easier verification, typing, modularity, and determinism. Please also see json-structure.org

Maintainers

Package info

github.com/Ric16Fr/laravel-json-structure

Type:libary

pkg:composer/ricfr/json-structure

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-07-25 19:30 UTC

This package is auto-updated.

Last update: 2026-07-26 06:18:05 UTC


README

Laravel Json Structure

Packagist PHP from Packagist GitHub Workflow Status (main) Total Downloads

This Package validates Laravel Requests against the new JSON Structure Specification which provides easier verification, typing, modularity, and determinism. Please also see json-structure.org for more information and also https://json-structure.org/codegen.html for how to turn classes into a structure and vies verta.

It aims to replace Laravels own ->verify() method with this emerging standard for several progamming languages.

Installation

You can install the package via Composer:

composer require ricfr/json-structure

Usage

Creating the structure document

To verify a JSON from a request against a structure, you'll first need to create one. Use

\LaravelJsonStructure\LaravelJsonStructure\Logic\JSONStructure::createFromObject($struct) 

to create a structure document from an PHP array. Thats usually the case when you either have the structure document defined by yourself (see the second link above to automate this) or you are reccieving the structure from an endpoint as well-

Or you can use

\LaravelJsonStructure\LaravelJsonStructure\Logic\JSONStructure::createFromFile($pathToFile) 

when you got the structure in form of a JSON file somewhere. Which happens usually when a colleague (from backend or so) creates it and sends it over.

Verifying a Request

You can then validate a Laravel Request object against a created JSONStructure Object by calling

$request->validateWithJSONStructure($structure)

This will return an array with all validation errors, meaning that if its empty the validation was succesfull.

Alternatively you can also skip the first step and call

$request->validateWithUncheckedJSONStructure($structureAsArray)

to directly insert the Structure definiton as an array and not create a structure object out of it. This ist not reccomended though, since it skips the validation of the structure itself. But it may be usefull for structure definitions not totally complying to the standard (yet).

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Laravel Json Structure! Please review our contributing guide to get started.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Laravel Json Structure is open-sourced software licensed under the GPL 3.0 license.