JSON Schema Validation
The specifications for them are taken from JSON Schema Validation: A Vocabulary for Structural Validation of JSON (draft 1). All of described assertions are implemented:
oneOf-- Values must conform to a specific number of the provided schemas.
const-- Values must be equal to the one in the schema.
contains-- At least one value in an array conforms to the schema.
dependencies-- Object property checks depending on which exist in the data.
enum-- Values must be in the specified set.
else-- conditional evaluation of schemas.
additionalItems-- Array items must confirm to the provided schemas.
multipleOf-- Value bounds checks for numeric data.
minItems-- bounds for the number of items in a JSON array.
minLength-- bounds for the number of code points in a string value.
minProperties-- counts for properties in a JSON object.
not-- negates the contained check.
pattern-- The regex must be found in a string value.
additionalProperties-- that the assertions for each property hold if present in the JSON object data.
propertyNames-- names of object properties must conform to the provided schema.
required-- Object properties must include the specified strings.
type-- type check against the JSON types (
uniqueItems-- All values in an array are unique.
The schema used for testing is http://json-schema.org/draft-07/schema#.
For type validation, if the underlying memory type is a
double then it will only match against
number even if there is no fractional part to the number. The JSON parser will correctly identify integers parsing JSON (and use the
int64_t memory type for them), so this can only happen when JSON is produced by code that uses a
double. The memory type
int64_t will match both of the
integer validation types.
The handling of
$id is particularly nasty. Although this implementation passes the test suite there are a large number of edge cases with the interactions between
$id that are not tested or covered. Our recommendation is to avoid use of
$id except for a full URL at schema root if required.
The JSON Schema Testsuite
The build target
json-schema-testsuite will download and run the tests that are found at the JSON Schema Test Suite.