Class Standards.JSON5.Validator
- Description
An instance of this class can be used to validate a JSON5 object against a JSON5 schema.
- Example
string schema_s = "{\n" + " \"name\": \"SomeExample\",\n" + " \"type\": \"object\",\n" + " \"properties\": {\n" + " \"name\": { \"type\": \"string\" },\n" + " \"id\": {\n" + " \"type\": \"integer\",\n" + " \"minimum\": 0\n" + " }\n" + " }\n" + "}"; string example_s = "{\n" + " \"name\": \"An Example\",\n" + " \"id\": 17\n" + "}"; mixed schema = Standards.JSON5.decode(schema_s); mixed example = Standards.JSON5.decode(example_s); if (string error = Standards.JSON5.Validator(schema).validate(example)) werror("Error: JSON5 string %O did not validate: %s\n", example_s, error); else write("JSON5 ok\n");
- Note
This class validates only a subset of the JSON5 schema specification. Currently dependencies and references are not handled and regular expressions (for pattern properties) are limited to those that can be handled by Regexp.SimpleRegexp.
For more information of JSON5 schema look at http://json5-schema.org/documentation.html "The home of JSON5 Schema".
- Method
create
Standards.JSON5.Validator Standards.JSON5.Validator(
mixed
_schema
)- Description
Create a JSON5 validator for some JSON5 schema.
- Parameter
_schema
The JSON5 schema to use in validate(). This must be a valid JSON5 object.
- Throws
Throws an error if the schema is invalid.