Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

## Usage

$json = json_decode($input_json);
$schema = json_decode($input_schema);
$result = JsonSchema::validate($json, $schema);

if ($result->valid) {
```php
<?php

$json = json_decode($input_json);
$schema = json_decode($input_schema);
$result = JsonSchema::validate($json, $schema);

if ($result->valid) {
die('success!');
}
else {
}
else {
die('fail...');
}
}
```
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "justinrainbow/json-schema",
"description": "a library to validate a json schema"
"keywords": ["json", "schema"],
"homepage": "https://github.com/justinrainbow/json-schema",
"type": "library",
"license": "MIT",
"version": "1.0.0",
"authors": [
{
"name": "Justin Rainbow"
}
],

"autoload": {
"psr-0": { "JsonSchema": "libs/", "JsonSchemaUndefined": "libs/"}
}
}

2 changes: 1 addition & 1 deletion libs/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static function checkProp($value, $schema, $path, $i = '', $_changing = false) {
}
// verify optional values
if (is_object($value) && $value instanceOf JsonSchemaUndefined) {
if ( isset($schema->optional) ? !$schema->optional : true) {
if ( isset($schema->required) ? !$schema->required : true) {
self::adderror($path,"is missing and it is not optional");
}
}
Expand Down