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.
You can install the package via Composer:
composer require ricfr/json-structureTo 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.
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).
Please see CHANGELOG for more information on what has changed recently.
Thank you for considering contributing to Laravel Json Structure! Please review our contributing guide to get started.
Please review our security policy on how to report security vulnerabilities.
Laravel Json Structure is open-sourced software licensed under the GPL 3.0 license.