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

Validation

The 'additionalProperties' keyword may be a boolean (true, false) value or a schema object.

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'.

Graphical Representation

 The UI simplifies the properties and displays them in a logical way, but if you are already familiar with the JSON standard this section describes how the UI is mapped from the source.

Additional Properties is false

Sample Json Schema
Copy Code
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "My schema",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "MyBooleanProperty": {
            "type": "boolean"
        },
        "MyArrayProperty": {
            "type": "array"
        }
    },
    "patternProperties": {
        "MyStringProperty[0-9]*": {
            "type": "string"
        }
    }
}

Shown graphically this looks like this 

When 'additionalProperties' is set to false it does not appear in the properties container.

 To add the 'additionalProperties' keyword back into the schema you can use the 'Add Properties -> Additional Properties' command from the context menu in the parent schema or the properties container (this will give the schema below).

 

Additional Properties is true

Sample Json Schema
Copy Code
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "My schema",
    "type": "object",
    "additionalProperties": true,
    "properties": {
        "MyBooleanProperty": {
            "type": "boolean"
        },
        "MyArrayProperty": {
            "type": "array"
        }
    },
    "patternProperties": {
        "MyStringProperty[0-9]*": {
            "type": "string"
        }
    }
}

Shown graphically this looks like this 

The <Additional Properties> node would also be displayed the same way if the 'additionalProperties' keyword was missing (as it defaults to true), in this case the Any* is displayed.

Converting 'additionaProperties' back to 'false' can be done by deleting it from the diagram.

To change the representation of 'additionaProperties' from an object to a boolean, the Representation property can be set.

 

Additional Properties contains a schema

Sample Json Schema
Copy Code
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "My schema",
    "type": "object",
    "additionalProperties": {
        "type": "number"
    },
    "properties": {
        "MyBooleanProperty": {
            "type": "boolean"
        },
        "MyArrayProperty": {
            "type": "array"
        }
    },
    "patternProperties": {
        "MyStringProperty[0-9]*": {
            "type": "string"
        }
    }
}

Shown graphically this looks like this 

The <Additional Properties> entry now holds a schema and can be edited as any other schema.

To make the 'additionaProperties' to false, you can just delete it, or change the representation using the Representation property.

  

See Also

Notation