Liquid XML Studio 2019
Required Property
JSON Schema Editor > Graphical Notation Overview > Properties Container > Required Property
Draft 04 Draft 06 Draft 07

A required property can exist within even when it is not explicitly defined within the schemas Properties Container.

This means it is required in the instance object either because it matches a patternProperty or because the schema allows additional properties.

Source Code
Copy Code
{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "title": "My schema",
    "additionalProperties": false,
    "patternProperties": {
        "MyProperty[0-1]*": {
            "type": "string"
        }
    },
    "required": [ "MyProperty1" ]
}

In this example the patternProperty "MyProperty[0-1]*" allows properties to exist which start with "MyProperty" and have a number on the end.

Lets assume we want as many "MyProperty" entries as we like, but we to ensure one exists called "MyProperty1".

By adding "MyProperty1" as a required property we ensure it must exist and validate against the rules in the patternProperty (i.e. its a string).

All required properties are drawn with a solid line around them, optional properties are drawn with a dotted line.

Required properties can be added via the properties right click menu

For more detail see the 'required' keyword.

For more in depth information regarding see the keywords properties, patternProperties, additionalProperties and propertyNames.

 

See Also

Object Constraints