aipng/json-validator

json validator (based on opis/json-schema)

1.2 2024-02-19 23:22 UTC

This package is auto-updated.

Last update: 2024-12-20 01:14:22 UTC


README

JSON validator (based on opis/json-schema)

Installation

composer require aipng/json-validator

Usage

Simple - validate JSON input against simple JSON schema

    use \AipNg\JsonValidator\JsonValidator;
    
    $validator = new JsonValidator;
    
    $validator->validate($jsonData, $jsonSchemaPath);

Validator provides simple mapping of JSON schema indentificators to a directory structure, eg:

    use \AipNg\JsonValidator\JsonValidator;
    
    $validator = new JsonValidator(10, 'https://example.org/schemas/', '/<my-project-schema-path/');
    
    $validator->validate($jsonData, $jsonSchemaPath);

Nette extension

Register

extensions:
	jsonValidator: AipNg\JsonValidator\DI\JsonValidatorExtension

Configure

jsonValidator:
	max_errors: 10              # maximum of returned errors
	mapping:                    # maps JSON schema identificators to directory structure
		prefix: https://www.example.org/api/schema/
		directory: %wwwDir%/../src/schema/