Create a json schema to validate against

Code
<?php

use JsonSchema\Uri\UriRetriever;
use 
JsonSchema\Validator;

// json config which should be valid to the schema
$data = <<<EOT
{
    "name": "foo",
    "value": "bar"
}
EOT;

$wrongdata = <<<EOT
{
    "name": "foo",
    "value": "bar",
    "foobarbaz": "value"
}
EOT;

// the json schema
$schemaPath __DIR__ '/resources/jsonschema.json';
dump(file_get_contents($schemaPath));

// retrieve schema for validation
$retriever = new UriRetriever();
$schema $retriever->retrieve('file://' $schemaPath);

$validator = new Validator();

// do the schema validation
$validator->check(json_decode($data), $schema);
dump($validator->isValid());

$validator->check(json_decode($wrongdata), $schema);
dump($validator->isValid());
dump($validator->getErrors());
Result
^ """
{\r\n
    "name": "Config",\n
    "type": "object",\n
    "additionalProperties": false,\n
    "properties": {\n
        "name": {\n
            "type": "string",\n
            "description": "Name of the option",\r\n
            "required": true\r\n
        },\r\n
        "value": {\n
            "description": "value of the option",\r\n
            "type": "string",\n
            "required": true\n
        }\n
    }\n
}\n
"""
^ true
^ false
^ array:1 [
  0 => array:5 [
    "property" => ""
    "pointer" => ""
    "message" => "The property foobarbaz is not defined and the definition does not allow additional properties"
    "constraint" => "additionalProp"
    "context" => 1
  ]
]
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8