Skip to main content

Lists

This schema snippet shows how to define different types of list in a content type schema using the array keyword, including lists of strings, images and content items.

  • For each of properties we use the minItems and maxItems validation keywords to specify how many items can be added to the list. The type of content that can be added is defined by the items keyword.

  • If you want to ensure that the user enters at least one value for a list set minItems to your required number of items and include the property in the required fields. See the listOfStrings property below for an example of how to do this.

  • The listOfEnums property uses the unique keyword. This property allows the user to choose a list of values using pre-defined values. Each value can only be chosen once.

Pre-requisites
Link copied!

This is a self contained example that you can modify to meet your own requirements.

How to use
Link copied!

To use the listOfContentItems property, the media example must be registered (https://schema-examples.com/media). Alternatively you can modify listOfContentItems to include one of your own content types.

Lists example schema
Link copied!

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://schema-examples.com/lists",

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

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

"type": "object",
"properties": {
"listOfStrings": {
"$comment": "A list of up to 5 strings of between 5 and 20 characters. This property is required",
"title": "String title",
"description": "Enter a string value",
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": {
"type": "string",
"minLength": 5,
"maxLength": 20
}
},
"listOfEnums": {
"$comment": "A list of up to 3 values chosen from an enum. Each value must be unique",
"title": "Values",
"description": "Choose up to 3 values",
"type": "array",
"minItems": 0,
"maxItems": 3,
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"Value one",
"Value two",
"Value three",
"Value four",
"Value five"
]
}
},
"listOfImages": {
"$comment": "A list of links to images in the user's media library",
"title": "Images",
"type": "array",
"minItems": 0,
"maxItems": 4,
"items": {
"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
}
]
}
},
"listOfContentItems": {
"$comment": "A list of links to media content items",
"title": "Media list",
"type": "array",
"minItems": 0,
"maxItems": 5,
"items": {
"allOf": [
{
"$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
},
{
"properties": {
"contentType": {
"enum": ["https://schema-examples.com/media"]
}
}
}
]
}
}
},
"propertyOrder": [],

"required": ["listOfStrings"]
}

Content form preview
Link copied!

An example of creating a content item using a content type registered from the lists example schema is shown in the image below.

Adding a content item from the lists example schema

Validation

Strings

Media and content choosers