Text

This schema snippet shows how to add text properties and includes some of the different types of validation available to you, including patterns and enums.

  • The dateWithPattern and urlslug properties demonstrate how to constrain the value entered using a regular expression defined by the pattern keyword. You can find out more about regular expressions in JSON Schema in the JSON Schema documentation.

  • The color property shows how to define a property that allows the user to choose a color using the color picker. This is a Dynamic Content specific addition to JSON Schema. The color is returned in RGB format, for example: rgb(64, 100, 127).

  • The dateFormat property defines a date using the "date" format introduced in JSON Schema draft 7. We use the examples keyword to give the user some example dates in the correct format.

Pre-requisites

None. This is a self contained schema.

How to use

This example demonstrates most of the available string formats and validations. You should be able to modify any of these properties for use in your own schemas.

Text schema example

{
  "$schema":"http://json-schema.org/draft-07/schema#",
  "$id":"https://schema-examples.com/text",
  "title":"Title",
  "description":"Description",
  "allOf":[
    {
      "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content"
    }
  ],
  "type":"object",
  "properties":{
    "stringWithMinMax":{
      "title":"String with min and max",
      "description":"Enter a string (0 to 255 characters)",
      "type":"string",
      "minLength":0,
      "maxLength":255
    },
    "richTextString":{
      "title":"Rich text string",
      "description":"Enter text using rich text or markdown",
      "type":"string",
      "format":"markdown"
    },
    "uriExample":{
      "title":"uri",
      "description":"A full URL (https://yourdomain.com/productpage)",
      "type":"string",
      "format":"uri",
      "maxLength":100
    },
    "dateWithPattern":{
      "$comment":"A date constrained using a regular expression specified by the pattern",
      "title":"Date",
      "description":"Enter a date(YYYY-MM-DD)",
      "type":"string",
      "maxLength":10,
      "minLength":10,
      "pattern":"^[0-9]{4}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))$"
    },
    "urlslug":{
      "$comment":"A string constrained to be an alphanumeric URL slug",
      "title":"URL slug",
      "description":"URL slug (a-z and 0-9)",
      "type":"string",
      "minLength":1,
      "maxLength":100,
      "pattern":"^[a-z0-9-]+$"
    },
    "stringFromEnum":{
      "title":"String value",
      "description":"Choose a string value from the list",
      "type":"string",
      "enum":[
        "String Value 1",
        "String Value 2",
        "String Value 3",
        "String Value 4"
      ]
    },
    "color":{
      "$comment":"A string constrained to be an alphanumeric URL slug",
      "title":"Color",
      "description":"Pick a color",
      "type":"string",
      "format":"color"
    },
    "dateFormat":{
      "$comment":"A string property with the date format",
      "title":"Date",
      "description":"Enter the date",
      "type":"string",
      "minLength":0,
      "maxLength":50,
      "format":"date",
      "examples":[
        "2019-10-15",
        "2018-07-31"
      ]
    },
    "stringConstant":{
      "title":"String constant",
      "description":"A string value that cannot be edited",
      "type":"string",
      "const":"United Kingdom"
    }
  },
  "propertyOrder":[

  ]
}

Content form preview

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

Adding a content item from the text example schema
Adding a content item from the text example schema

Strings

JSON Schema regular expressions

results matching ""

    No results matching ""