File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## JsonSchema\Validator Demo
2
+
3
+ This demo script uses the example from the root README.md and provides sample JSON files for testing ` JsonSchema\Validator ` .
4
+
5
+ To change or replace the JSON schema document, please edit ` /path/to/json-schema/demo/schema.json ` .
6
+
7
+ To change or replace the JSON document that is validated, please edit ` /path/to/json-schema/demo/data.json ` .
8
+
9
+ To run the demo, change the path in the following example and run it in your terminal.
10
+
11
+ ```
12
+ cd /path/to/json-schema/demo
13
+ php demo.php // The supplied JSON validates against the schema.
14
+ ```
Original file line number Diff line number Diff line change
1
+ {
2
+ "foo" :" bar"
3
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ require (__DIR__ . '/../vendor/autoload.php ' );
3
+
4
+ $ data = json_decode (file_get_contents ('data.json ' ));
5
+
6
+ // Validate
7
+ $ validator = new JsonSchema \Validator ;
8
+ $ validator ->check ($ data , (object )['$ref ' => 'file:// ' . realpath ('schema.json ' )]);
9
+
10
+ if ($ validator ->isValid ()) {
11
+ echo "The supplied JSON validates against the schema. \n" ;
12
+ } else {
13
+ echo "JSON does not validate. Violations: \n" ;
14
+ foreach ($ validator ->getErrors () as $ error ) {
15
+ echo sprintf ("[%s] %s \n" , $ error ['property ' ], $ error ['message ' ]);
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " object"
3
+ }
You can’t perform that action at this time.
0 commit comments