Skip to main content

Numbers schema example

This schema example shows how to define integer and number properties and apply validation using the minimum, maximum, and multipleOf keywords to constrain user input. It also demonstrates the use of UI components, including a slider and a dropdown with labels, along with example component parameters.

Note

In Dynamic Content, integers must be whole numbers. For example, 1.0 is not a valid integer.

The exclusiveMaximum and exclusiveMinimum validation keywords are not currently supported.

Pre-requisites
Link copied!

This is a self contained schema that uses standard JSON Schema property types and validations.

How to use
Link copied!

You can change the validation of each property to meet your own requirements.

Integer and number 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/numbers",
    "title": "Title",
    "description": "Description",
    "allOf": [
    {
    "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content"
    }
    ],
    "type": "object",
    "properties": {
    "integerWithRange": {
    "title": "Simple integer",
    "description": "An integer between 1 and 15",
    "type": "integer",
    "minimum": 1,
    "maximum": 15
    },
    "integerMultipleOf10": {
    "title": "Integer multiple",
    "description": "An integer between 1 and 100. A multiple of 10",
    "type": "integer",
    "minimum": 10,
    "maximum": 100,
    "multipleOf": 10
    },
    "numberWithRange": {
    "title": "Number with range",
    "description": "A number between 35.2 and 39.6",
    "type": "number",
    "minimum": 35.2,
    "maximum": 39.6
    },
    "numberWithNegativeMin": {
    "title": "Number with negative min",
    "description": "A number that must be >= -25",
    "type": "number",
    "minimum": -25
    },
    "percentValue": {
    "type": "integer",
    "title": "Percentage",
    "description": "Shows use of the suffix parameter",
    "examples": [
    "20%",
    "40%",
    "65%"
    ],
    "minimum": 0,
    "maximum": 100,
    "ui:component": {
    "params": {
    "placeholder": "50%",
    "variant": "filled",
    "suffix": "%",
    "allowNegative": false
    }
    }
    },
    "temperature": {
    "type": "number",
    "title": "Number Temperature",
    "examples": [
    "2.5",
    "3.7"
    ],
    "minimum": -10,
    "maximum": 10,
    "ui:component": {
    "params": {
    "suffix": "\u00b0",
    "allowNegative": true,
    "step": 0.1,
    "precision": 1
    }
    }
    },
    "sliderInteger": {
    "type": "integer",
    "description": "A slider with labels",
    "ui:component": {
    "name": "slider",
    "params": {
    "placeholder": "Some useful initial text",
    "inverted": false,
    "color": "",
    "marks": [
    {
    "value": 0,
    "label": "Transparent"
    },
    {
    "value": 25,
    "label": "Faint"
    },
    {
    "value": 50,
    "label": "Light"
    },
    {
    "value": 75,
    "label": "Dark"
    },
    {
    "value": 100,
    "label": "Solid"
    }
    ],
    "step": 25
    }
    }
    },
    "labelledListWithDecimals": {
    "title": "Decimal dropdown with labels",
    "description": "A dropdown with user friendly labels",
    "type": "number",
    "oneOf": [
    {
    "title": "Low",
    "const": 0.45
    },
    {
    "title": "Medium",
    "const": 0.75
    },
    {
    "title": "High",
    "const": 0.85
    }
    ]
    }
    },
    "propertyOrder": []
    }

    Validation keywords

    Input field component reference