Welcome to JsonSchema’s documentation!¶
Contents:
Installation¶
git clone https://github.com/justinrainbow/json-schema.git
Composer method¶
Add the justinrainbow/json-schema package to your composer.json file.
{
"require": {
"justinrainbow/json-schema": "1.1.*"
}
}
Then just run the usual php composer.phar install to install.
Usage¶
<?php
$validator = new JsonSchema\Validator();
$result = $validator->validate(json_decode($json), json_decode($schema));
if ($result->valid) {
echo "The supplied JSON validates against the schema.\n";
} else {
echo "JSON does not validate. Violations:\n";
foreach ($result->errors as $error) {
echo "[{$error['property']}] {$error['message']}\n";
}
}