Additionalproperties - sgpinkus/json-schema GitHub Wiki
THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.
NOTE: This proposal was incorporated into Draft 04
The validity of an object instance with regards to this keyword depends on its value:
- if it is boolean true or an object, then validation of the instance always succeeds;
- if it is boolean false, then the members (keys) of both properties and patternProperties must be considered, see below.
The value for additionalProperties MUST be a boolean or an object. If it is an object, then this object MUST be a valid JSON Schema.
Boolean value true MAY be considered the same as an empty schema.
This is an example algorithm to determine if the instance is valid:
- construct the following sets:
- s: the set of members of the instance to validate;
- p: the set of members of the properties keyword value (if any);
- pp: the set of members of the patternProperties keyword value (if any);
- remove from s all values in p;
- for each value in pp (which is an ECMA 262 regular expression, see pattern):
- grab a value of s;
- try and match it against the regular expression: if it matches, remove it from s;
- the instance is valid if and only if, at this stage, s is empty.
Consider the following schema (note: the regular expression \d matches a single digit):
{
"properties": {
"p1": {}
},
"patternProperties": {
"p": {},
"\\\\d": {}
}
}
and the following instance to validate:
{
"p1": true,
"p2": null,
"a32&o": "foobar",
"": "yep, that's a valid member name",
"finance": "sucks",
"apple": "victim"
}
The three sets as described by the algorithm above are:
- s: { "p1", "p2", "a32&o", "", "finance", "apple" };
- p: { "p1" };
- pp: { "p", "\\d" }.
After the first step of the algorithm, "p1" is removed from s, which is now:
{ "p2", "a32&o", "", "finance", "apple" }
For the second step:
- "p" matches "p2";
- "\\d" matches "a32&o";
- "p" matches "apple".
Which means s is left with the following values:
{ "", "finance" }
It is therefore nonempty, which means validation fails.