Skip to main content

Default keyword schema example

This schema example shows how to use the default keyword to set initial values for items. You can use the default keyword with strings, numbers, booleans and lists, as well as content and image links.

Pre-requisites
Link copied!

None. This is a self contained schema.

How to use
Link copied!

Use the examples in this schema as a starting point for applying default values to your own properties.

Info

To use the example-image-link and example-content-link properties, you will need to update these properties to use an image and a content item from your own hub.

In the example-image-link property, the default value includes all the properties returned by an image-link object, including the id, name, endpoint and default host. The easiest way to find all these values is to publish a content item containing the image and view the item in JSON format from a link in the "Content delivery" section of the content form. See content item properties for more details.

For the example-content-link property you can also find the contentType and id fields from the content item properties window and use these values to define a default content-link.

Defaults example
Link copied!

Interactive

This example is best viewed on a desktop browser where the schema editor is fully interactive.

    Schema source
    {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://schema-examples.com/default",
    "title": "Default keyword",
    "description": "Examples of using the default keyword",
    "$comment": "Docs: https://amplience.com/docs/development/schema-examples/core-concepts/default.html",
    "allOf": [
    {
    "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content"
    }
    ],
    "type": "object",
    "properties": {
    "numberValue": {
    "title": "Number value",
    "description": "A number value between 0 and 100 with a default set",
    "type": "number",
    "minimum": 0,
    "maximum": 100,
    "default": 90
    },
    "stringProperty": {
    "title": "A string with a default value",
    "type": "string",
    "minLength": 0,
    "maxLength": 20,
    "default": "Some example text"
    },
    "rich-text-item": {
    "title": "Rich text",
    "type": "string",
    "format": "markdown",
    "default": "Lorem ipsum dolor sit amet\u2026"
    },
    "example-enum": {
    "type": "string",
    "enum": [
    "chair",
    "sofa",
    "bed",
    "table",
    "lamp"
    ],
    "default": "sofa"
    },
    "string-Array": {
    "title": "String array",
    "description": "An array of strings with default values",
    "type": "array",
    "items": {
    "type": "string"
    },
    "default": [
    "string",
    "string1",
    "string2"
    ]
    },
    "color": {
    "title": "Color",
    "format": "color",
    "type": "string",
    "default": "rgb(255, 102, 102)"
    },
    "example-boolean": {
    "title": "Example boolean",
    "type": "boolean",
    "default": true
    },
    "example-image-link": {
    "allOf": [
    {
    "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
    }
    ],
    "default": {
    "_meta": {
    "schema": "http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
    },
    "id": "286e4760-1812-4e3a-81ab-d2e3bf32b9b5",
    "name": "blue-tie",
    "endpoint": "ampproduct",
    "defaultHost": "cdn.media.amplience.net"
    }
    },
    "example-content-link": {
    "allOf": [
    {
    "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
    },
    {
    "properties": {
    "contentType": {
    "enum": [
    "http://docexample.com/tutorialbanner.json"
    ]
    }
    }
    }
    ],
    "default": {
    "_meta": {
    "schema": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
    },
    "contentType": "http://docexample.com/tutorialbanner.json",
    "id": "12058184-97de-42e7-93b5-29b8705a871d"
    }
    }
    },
    "propertyOrder": []
    }

    Default keyword