Generic keywords

To use the keywords included in this page, you will need to edit the value of $schema to specify that you are using the updated schema vocabulary of JSON Schema Draft 7. See the content type schema format page for more details and the combined example at the end of this page.

Examples

The examples keyword allows developers to include an array of example acceptable values for a property. These examples are then displayed in the content editing window in the production view as hints to the user.

A property including examples is shown below. This is a string with date format for which some sample valid values have been provided.

"date": {
    "title": "date",
    "description": "description",
    "type": "string",
    "minLength": 0,
    "maxLength": 50,
    "format": "date",
    "examples": [
        "2019-10-15",
        "2018-07-31"
    ]
}

In the content editing window, any properties with examples will be displayed with a "i" icon to the right of the property. Click this icon to display the examples in a pop up window.

The image below shows a string property which uses the date format. The content type schema included examples for this property using the acceptable date format- full year, month and day.

Examples don't change the functionality or validation of a schema, but they do provide useful hints to the user.

The examples keyword allows a developer to provide sample values for a property. These are displayed in the content editing window in the production view.

The values included in the examples for a property are also used to populate the data shown in the "Sample output" window of the Schema Editor.

Sample JSON output populated from the examples for a property.

Comments

Comments can be added to a property or at the root level of a schema using the $comment keyword. They are not shown in the content editing form and do not affect the functionality of the schema. Comments are intended to provide notes to developers maintaining a schema.

"date": {
    "title": "date",
    "description": "description",
    "type": "string",
    "minLength": 0,
    "maxLength": 50,
    "format": "date",
    "examples": [
        "2019-10-15",
        "2018-07-31"
    ],
    "$comment": "A string property with the date format"
}

Constants

The const keyword is used to specify the value of a property and indicate that it cannot be changed. You can use const with strings, numbers and other property types such as media links. For example, you could specify a set image that is always included with a content type, or some settings that cannot be changed.

The example below shows a shippingcountry property is defined as a string with the value of "United Kingdom".

"shippingcountry": {
    "title": "Ship to",
    "description": "description",
    "type": "string",
    "const": "United Kingdom"
        }

You can add const properties using the Schema Editor by choosing "const" from the "Add Property" menu and choosing to add a text string or a number.

Adding a const in the Schema Editor

The property defined above will be displayed in the schema preview window and the content editing window as shown below. The value cannot be changed by the user.

Adding a const in the Schema Editor

const arrays

To specify an array of constants you could define a property as follows:

"conststringarray": {
    "type": "array",
    "const": [
        "one",
        "two"
    ],
    "items": {
        "type": "string"
    }
}

This property will be displayed in the content editing window as shown below. The user will not be able to edit the values in the array.

An array of string constants

Combined example

A content type schema that makes use of $comment, examples and const is shown below.

{
    "$schema": "http://bigcontent.io/cms/schema/v2/schema#",
    "$id": "http://example.com/stringformats.json",

    "title": "Title",
    "description": "Description",

    "allOf": [
        {
            "$ref": "http://bigcontent.io/cms/schema/v2/core#/definitions/content"
        }
    ],

    "type": "object",
    "properties": {
        "date": {
            "title": "date",
            "description": "description",
            "type": "string",
            "minLength": 0,
            "maxLength": 50,
            "format": "date",
            "examples": [
                "2019-10-15",
                "2018-07-31"
            ],
            "$comment": "A string property with the date format"
        },
        "shippingcountry": {
            "title": "Ship to",
            "description": "description",
            "type": "string",
            "const": "United Kingdom"
        }


    },
    "propertyOrder": []
}

results matching ""

    No results matching ""