PHP code example of ergebnis / json-schema-validator

1. Go to this page and download the library: Download ergebnis/json-schema-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ergebnis / json-schema-validator example snippets




declare(strict_types=1);

use Ergebnis\Json\Json;
use Ergebnis\Json\Pointer;
use Ergebnis\Json\SchemaValidator;

$json = Json::fromFile('composer.json');
$schema = Json::fromString(file_get_contents('https://getcomposer.org/schema.json'));
$jsonPointer = Pointer\JsonPointer::document();

$schemaValidator = new SchemaValidator\SchemaValidator();

$result = $schemaValidator->validate(
    $json,
    $schema,
    $jsonPointer
);

var_dump($result->isValid()); // bool
var_dump($result->errors());  // flat list of `ValidationError` value objects