Json decoding/encoding against a schema with Webmozart/Json

Code
<?php

use Webmozart\Json\JsonEncoder;
use 
Webmozart\Json\JsonDecoder;

$data = [
    
'name' => 'foo',
    
'value' => 'bar',
];

$wrongdata = [
    
'name' => 'foo',
    
'value' => 'bar',
    
'foobarbaz' => 'value',
];

// the json schema
$schemaPath __DIR__ '/resources/jsonschema.json';
echo 
'<pre>' file_get_contents($schemaPath) . '</pre>';

$encoder = new JsonEncoder();

// JSON encoding
$json $encoder->encode((object) $data$schemaPath);
dump($json);

// failed encoding that doesn't fit to schema
try {
    
$encoder->encode((object) $wrongdata$schemaPath);
} catch (
Exception $e) {
    echo 
'<pre>' $e->getMessage() . '</pre>';
}

$decoder = new JsonDecoder();
// JSON decoding
dump($decoder->decode($json$schemaPath));
Result
{
    "name": "Config",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "name": {
            "type": "string",
            "description": "Name of the option",
            "required": true
        },
        "value": {
            "description": "value of the option",
            "type": "string",
            "required": true
        }
    }
}
"{"name":"foo","value":"bar"}"
Validation of the JSON data failed:
The property foobarbaz is not defined and the definition does not allow additional properties
{#460
  +"name": "foo"
  +"value": "bar"
}