The Number input type

In JSON Schema, the number type is used to describe properties that must have numeric values. Unlike the integer type, number allows for fractional parts, providing flexibility for properties that can have non-integer values.

For more information about the Number type in JSON schema, read JSON Schema - Number.

Schema definition

To define a property as a number in JSON Schema, you use the "type" keyword with the value "number".

"input": {
    "type": "object",
    "properties": {
        "NumberFieldName": {
            "title": "example number input",
            "type": "number",
            "description": "an explanation of what this field is."
        }
    },
    "required": []
},

This example also demonstrates how to provide a description and title to the Number field for use within the editing interface.

Basic number constraints

There are three types of basic number constraints:

  • Minimum and maximum values

  • Exclusive minimum and maximum values

  • Multiple of. === Minimum and maximum values You can constrain the value range of a number using the "minimum" and "maximum" keywords:

"input": {
    "type": "object",
    "properties": {
        "numberFieldName": {
            "type": "number",
            "minimum": 0.7,
            "maximum": 99.3
        }
    },
    "required": []
},

This example ensures that the number value falls between 0.7 and 99.3 (inclusive).

Exclusive minimum and maximum values

You can constrain the value range of a number using the "minimum" and "maximum" keywords:

"input": {
    "type": "object",
    "properties": {
        "numberFieldName": {
            "type": "number",
            "exclusiveMinimum": 11.1,
            "exclusiveMaximum": 77.3
        }
    },
    "required": []
},

This example excludes the values 11.1 and 77.3, allowing only values between those intervals.

Multiple of

The "multipleOf" keyword allows you to specify that the number value must be a multiple of a given number:

"input": {
    "type": "object",
    "properties": {
        "numberFieldName": {
            "type": "number",
            "multipleOf": 0.5
        }
    },
    "required": []
},

In this example, the number must be divisible evenly by 0.5.

Enumerated values

You can specify a list of valid number values using the "enum" keyword:

"input": {
    "type": "object",
    "properties": {
        "numberFieldName": {
            "type": "number",
            "enum": [42.3, 7.11, 11]
        }
    },
    "required": []
},

This ensures that the number can only take one of the specified values.

Default value

The "default" keyword allows you to provide a default value for an number property:

"input": {
    "type": "object",
    "properties": {
        "numberFieldName": {
            "type": "number",
            "default": 42.5
        }
    },
    "required": []
},

Editing interface

This image shows an example of the Number type input field in the editing interface.
Figure 1. The Number input types editing interface field.

Input object structure

The Number input type is available to consume in the main function through the input object. The Number field will output an number variable.

const input = {
  numberField: 42,
};

module.exports = async function (input) {
  return `
      <div>
        <p><b>Question:</b> How many roads must a man walk down, before you can call him a man?</p>
        <p><b>Answer:</b> ${input.numberField}</p>
      </div>`;
};

Full manifest definition

Expand to see the manifest.json file with a number input field
{
  "$schema": "http://localhost:3000/schemas/v1.json",
  "name": "myInt",
  "version": "1.0.0",
  "mainFunction": "main",
  "displayName": "Number example",
  "namespace": "number-component",
  "icon": {
  "id": "list_alt",
  "color": {
    "type": "hex",
    "value": "#2D2D2D"
    }
  },
  "description": "This component is set up as a demonstration component for documentation purposes.",
  "functions": [
    {
      "name": "main",
      "entry": "main.js",
      "input": {
        "type": "object",
        "properties": {
          "intField": {
            "type": "number",
            "default": 42
          }
        },
        "required": []
      },
      "output": { "responseType": "html" }
    }
  ],
  "previews":
    {
      "firstpreview": {
        "functionData": {
          "main": {
            "inputData": {
              "type": "inline",
              "value": {
                "intField": 42
              }
            },
            "wrapper": {
              "path": "preview-wrapper.html"
            }
          }
        }
      }
    }
   }