Liquid XML Studio 2019
Pattern Properties
JSON Schema Editor > Properties > Properties (by name) > Pattern Properties
Draft 04 Draft 06 Draft 07

Validation

The 'patternProperties' keyword contains 1 or more named schemas, the name of the schema represents a regular expression. The associated schema is used to validate instance members whose names match against the regular expressions.

The names (regular expressions) of the members within the 'patternProperties' collection must be unique.

From the Json Schema Standard Version 4 draft.

5.4.4.1.  Valid values

The value of "additionalProperties" MUST be a boolean or an object. If it is an object, it MUST also be a valid JSON Schema.

The value of "properties" MUST be an object. Each value of this object MUST be an object, and each object MUST be a valid JSON Schema.

The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. Each property value of this object MUST be an object, and each object MUST be a valid JSON Schema.

5.4.4.3.  Default values

Successful validation of an object instance against these three keywords depends on the value of "additionalProperties":

    if its value is boolean true or a schema, validation succeeds;

    if its value is boolean false, the algorithm to determine validation success is described below.

5.4.4.4.  If "additionalProperties" has boolean value false

In this case, validation of the instance depends on the property set of "properties" and "patternProperties". In this section, the property names of "patternProperties" will be called regexes for convenience.

The first step is to collect the following sets:

s
The property set of the instance to validate.
p
The property set from "properties".
pp
The property set from "patternProperties".

Having collected these three sets, the process is as follows:

remove from "s" all elements of "p", if any;

for each regex in "pp", remove all elements of "s" which this regex matches.

Validation of the instance succeeds if, after these two steps, set "s" is empty.

 

8.3.2.  Implied keywords

The three keywords implied in this calculation are "properties", "patternProperties" and "additionalProperties".

If "properties" or "patternProperties" are absent, they are considered present with an empty object as a value.

If "additionalProperties" is absent, it is considered present with an empty schema as a value. In addition, boolean value true is considered equivalent to an empty schema.

8.3.3.  Calculation

8.3.3.1.  Names used in this calculation

The calculation below uses the following names:

    m
        The property name of the child.
    p
        The property set from "properties".
    pp
        The property set from "patternProperties". Elements of this set will be called regexes for convenience.
    s
        The set of schemas for the child instance.

8.3.3.2.  First step: schemas in "properties"

If set "p" contains value "m", then the corresponding schema in "properties" is added to "s".

8.3.3.3.  Second step: schemas in "patternProperties"

For each regex in "pp", if it matches "m" successfully, the corresponding schema in "patternProperties" is added to "s".

8.3.3.4.  Third step: "additionalProperties"

The schema defined by "additionalProperties" is added to "s" if and only if, at this stage, "s" is empty.

 

Trying to simplify this;

When 'additionalProperties' is false.

The name of every member in the instance object must for full at least on of the following;

Furthermore:

If the instance object's member matches by name against a member in 'properties' then the instance value must validate against the corresponding schema.

If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.

 

When 'additionalProperties' is true or absent.

The instance object places no restriction on the names of the members it contains.

But:

If the instance object's member matches by name against a member in 'properties' then the instance value must validate against the corresponding schema.

If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.

 

When 'additionalProperties' is a schema.

The instance object places no restriction on the names of the members it contains.

But:

If the instance object's member matches by name a member in 'properties' then the instance value must validate against the corresponding schema.

If the instance object's member matches the regular expression given by the name of a member in 'patternProperties' then the instance value must validate against the corresponding schema.

The value of any instance object members whose name did not match against 'properties' or 'patternProperties' must validate against the schema contained in 'additionalProperties'.

 

See Also