Skip to content

Schema Validation

This document covers JSON Schema validation keywords that can be used in the Extra Schema Definitions field when setting up properties in a schema.

Total CMS uses JSON Schema (Draft 2020-12) for data validation. In addition to the basic schema properties (type, field, label, etc.), you can add validation constraints to ensure data quality and consistency.

Where to add these: In the Schema admin interface, when editing a property, use the Extra Schema Definitions field to add validation keywords as JSON.

Important: Validation keywords like pattern, minLength, maxLength, minimum, maximum, etc. must be added in the Extra Schema Definitions section of a property — not in the property’s Settings. The Settings section controls display and behavior options, while Extra Schema Definitions is where all JSON Schema validation rules go.

By default, required string and array fields are automatically validated:

  • Strings: Cannot be empty ("")
  • Arrays (list, gallery, deck): Cannot be empty ([])
  • Files/Images: Validated on the frontend (must have a file uploaded)

You can override this behavior by explicitly setting minLength or minItems.

Conditional required? The schema’s top-level required array is a hard data invariant enforced on every save. If you need a field that is only required when another field has a particular value (e.g. “email required only when notifications toggle is on”), use the form-level settings.required option paired with settings.visibility instead. See Required (Form-Level) in the All Fields docs.

Enforce minimum and maximum string length.

{
"minLength": 3,
"maxLength": 100
}

Example - Username field:

{
"username": {
"type": "string",
"field": "text",
"label": "Username",
"minLength": 3,
"maxLength": 20
}
}

Use cases:

  • Usernames (3-20 characters)
  • Product names (minimum 5 characters)
  • Short descriptions (maximum 200 characters)
  • Passwords (minimum 8 characters)

Validate strings against a regular expression.

Total CMS ships a registry of ready-made patterns. Reference one by name and it expands to the real regex when the schema is saved:

{
"release": {
"type": "string",
"field": "text",
"label": "Release",
"pattern": "patterns.version"
}
}

That stores ^\\d+\\.\\d+\\.\\d+$, so 3.5.0 is accepted and 3.5, v3.5.0 and junk-3.5.0-junk are all rejected.

These are the same names used by form fields, so a field and its schema stay on one definition. There are no backslashes to escape, and the expansion adds the ^ and $ anchors for you.

Frequently used names:

NameAccepts
patterns.version3.5.0
patterns.versionExtended3.5.0, v3.5.1-rc.1, 3.5.0+build.7
patterns.slugmy-post-title
patterns.uuid123e4567-e89b-42d3-a456-426614174000
patterns.hex#aabbcc
patterns.domaintotalcms.co
patterns.integer-42
patterns.phone.usa555-123-4567
patterns.postCode.ukSW1A 1AA

Nested patterns use their dotted path, exactly as in Twig. See Validation Patterns for the full list.

An unknown name is an error on save rather than a silently broken schema, so a typo like patterns.verison tells you immediately.

When no named pattern fits, write the regex yourself:

{
"slug": {
"type": "string",
"field": "text",
"label": "URL Slug",
"pattern": "^[a-z0-9-]+$"
}
}

Common patterns:

  • Alphanumeric: ^[a-zA-Z0-9]+$
  • URL-safe slug: ^[a-z0-9-]+$
  • Hex color: ^#[0-9A-Fa-f]{6}$
  • Phone (US): ^\\d{3}-\\d{3}-\\d{4}$
  • Version (x.y.z): ^\\d+\\.\\d+\\.\\d+$

Backslashes must be doubled. \\d is how you write \d in JSON — a single \d is not a legal JSON escape. The schema editor’s JSON field repairs a lone \d for you on save, but the doubled form is what is stored. Named patterns avoid the problem entirely.

Anchor your literal patterns. JSON Schema’s pattern is a substring match, not a full match. Without ^ and $, \\d+\\.\\d+\\.\\d+ happily accepts junk-3.5.0-junk. Named patterns are anchored for you.

Use built-in format validators.

{
"format": "email"
}

Available formats:

  • email - Email address
  • uri / url - URL
  • date - Date (YYYY-MM-DD)
  • time - Time (HH:MM:SS)
  • date-time - ISO 8601 date-time
  • ipv4 / ipv6 - IP address

Example:

{
"website": {
"type": "string",
"field": "url",
"label": "Website",
"format": "uri"
}
}

Enforce minimum and maximum numeric values.

{
"minimum": 0,
"maximum": 100
}

Example - Percentage field:

{
"discount": {
"type": "number",
"field": "number",
"label": "Discount %",
"minimum": 0,
"maximum": 100
}
}

Like minimum/maximum, but excludes the boundary value.

{
"exclusiveMinimum": 0,
"exclusiveMaximum": 100
}

Example - Temperature (must be above 0, not equal to 0):

{
"temperature": {
"type": "number",
"field": "number",
"label": "Temperature (°C)",
"exclusiveMinimum": 0
}
}

Ensure number is a multiple of a specified value.

{
"multipleOf": 5
}

Example - Quantity (in packs of 5):

{
"quantity": {
"type": "integer",
"field": "number",
"label": "Quantity",
"multipleOf": 5,
"minimum": 5
}
}

Enforce minimum and maximum array length.

{
"minItems": 1,
"maxItems": 10
}

Example - Tags field:

{
"tags": {
"$ref": "https://www.totalcms.co/schemas/properties/list.json",
"label": "Tags",
"minItems": 1,
"maxItems": 5
}
}

Use cases:

  • Tags (1-5 items)
  • Gallery (minimum 3 images)
  • Options (maximum 10 choices)
  • Team members (minimum 2 members)

Ensure all items in an array are unique.

{
"uniqueItems": true
}

Example - Category tags:

{
"categories": {
"$ref": "https://www.totalcms.co/schemas/properties/list.json",
"label": "Categories",
"uniqueItems": true
}
}

Note: The list property type already has uniqueItems: true by default.

Restrict values to a specific set of allowed options.

{
"enum": ["draft", "published", "archived"]
}

Example - Status field:

{
"status": {
"type": "string",
"field": "select",
"label": "Status",
"enum": ["draft", "published", "archived"],
"options": [
{"value": "draft", "label": "Draft"},
{"value": "published", "label": "Published"},
{"value": "archived", "label": "Archived"}
]
}
}

Use cases:

  • Predefined statuses
  • Size options (S, M, L, XL)
  • Priority levels (low, medium, high)
  • Content types

You can combine multiple validation keywords for comprehensive data validation.

Example - Product SKU:

{
"sku": {
"type": "string",
"field": "text",
"label": "Product SKU",
"minLength": 8,
"maxLength": 12,
"pattern": "^[A-Z]{3}-[0-9]{4,8}$"
}
}

Example - Price field:

{
"price": {
"type": "number",
"field": "number",
"label": "Price (USD)",
"minimum": 0.01,
"maximum": 999999.99,
"multipleOf": 0.01
}
}

Example - Feature list:

{
"features": {
"$ref": "https://www.totalcms.co/schemas/properties/list.json",
"label": "Product Features",
"minItems": 3,
"maxItems": 10,
"uniqueItems": true
}
}

Ensure that a property’s value is unique across all objects in the collection.

{
"unique": true
}

Example - Email field:

{
"email": {
"$ref": "https://www.totalcms.co/schemas/properties/email.json",
"label": "Email Address",
"unique": true
}
}

Example - Username field:

{
"username": {
"type": "string",
"field": "text",
"label": "Username",
"unique": true,
"minLength": 3,
"maxLength": 20
}
}

Important requirements:

  • Must be indexed: Unique properties must be included in the schema’s index array for performance
  • Case-sensitive: Uniqueness validation is case-sensitive (e.g., “[email protected]” and “[email protected]” are considered different)
  • Empty values allowed: Multiple objects can have empty/null values for a unique field
  • Update behavior: When updating an object, you can keep the same value, but cannot change to a value used by another object

Use cases:

  • User emails (prevent duplicate registrations)
  • Usernames (ensure unique login identifiers)
  • Product SKUs (avoid inventory conflicts)
  • Slug fields (ensure unique URLs)

Error message: When a duplicate value is detected, users will see an error message like:

Email must be unique. The value '[email protected]' already exists in another object.

Schema setup example with index:

{
"id": "user",
"type": "object",
"properties": {
"id": {
"type": "string",
"label": "ID",
"field": "id"
},
"email": {
"$ref": "https://www.totalcms.co/schemas/properties/email.json",
"label": "Email",
"unique": true
},
"username": {
"type": "string",
"label": "Username",
"field": "text",
"unique": true
}
},
"required": ["id", "email", "username"],
"index": ["id", "email", "username"]
}

Note: If you mark a property as unique but don’t include it in the index, you’ll receive a helpful error message prompting you to add it to the index.

Make a property admin-only. A user who is not a super admin cannot set it: on update the stored value is kept, on create the field is dropped, and the attempt is written to the access log. The rest of the save goes through, so a form that includes the field still works — the protected value just does not change.

{
"protected": true
}

Add a value to also force the property on every authenticated non-admin write (session or OAuth user), whether or not the request included it — the exceptions are listed under the rules below:

{
"protected": { "value": true }
}

Example — moderation flags:

{
"draft": {
"type": "boolean",
"label": "Draft",
"help": "Awaiting review. Every member edit sets it back to true.",
"field": "toggle",
"default": true,
"protected": { "value": true }
},
"featured": {
"type": "boolean",
"label": "Featured",
"help": "Editor's pick. Admins only.",
"field": "toggle",
"default": false,
"protected": true
}
}

With this, a member’s submission is a draft until an admin approves it, and any later edit by the member returns it to draft. The admin changes draft through the dashboard or API as usual. A member’s request to the protected property’s own route (PUT .../{id}/draft, or deleting, uploading into or editing deck items of that property) is refused with 403; a member’s request to any other property route (PUT .../{id}/title) succeeds and writes the forced values alongside.

Rules:

  • protected binds every writer who is not a super admin, on any collection. API keys and admin OAuth bearer tokens are trusted and not filtered. A bearer token issued to a non-admin user is treated as that user.
  • protected is honoured on top-level properties only. A protected flag inside a card or deck child schema is ignored.
  • Accepted shapes are true and an object with a value key. Anything else is reported by schema:lint and ignored at runtime.
  • A forced value still has to pass the property’s own validation.
  • A non-admin cannot clone an object in a collection that has protected properties, because a clone would copy values they cannot write. A public create does not make that clone public either. A non-admin clone whose body names a different target collection is refused on any collection.
  • A non-admin cannot import into a collection that has protected properties (/api/import/collections/{collection}/...: CSV, JSON, deck CSV, deck JSON and factory): an import upserts whole objects. Refused clones and imports are logged with reason: protected.
  • Over MCP, a collection with protected properties accepts writes (create_object, update_object, patch_object) from admin callers only.
  • Forced values apply to every authenticated non-admin write (session or OAuth user) — body routes, property routes, deck items, file and upload routes, meta writes and property deletes — in the same save, so editing title, adding a deck item or uploading a new image on an approved object still flips draft back to true. Anonymous public submissions through the object body routes are forced too. The exceptions: counter increments and decrements (a tick is not an edit), property, deck and file routes reached as a public submission under a public update, and registration, which strips protected fields but does not apply forced values.
  • The fields groups, active, expiration, maxLoginCount, passkeys, loginCount, lastlogin and created are always protected on auth schemas; no flag is needed.
  • A collection’s ownerProperty is protected by being named on the collection.

Make a property writable by the site only. Use it for values the site computes, such as an order total, a payment status or a rating average. Admins and API keys cannot set it either, because a wrong total is wrong whoever typed it.

"total": {
"type": "integer",
"field": "number",
"help": "Set at checkout",
"serverOnly": true
}
  • Every writer except the site’s own code is filtered: anonymous visitors, members, admins, API keys and MCP clients. This also applies when authentication is switched off. On update the stored value is kept, on create the field is dropped, and the attempt is written to the access log. The rest of the save goes through.
  • Code changes the field by writing as the system. In an extension, wrap the write in ActorContext::runAs(Actor::system(), fn () => ...).
  • Imports keep the values they carry. A JumpStart import, tcms push, or a CSV or JSON import by an admin or API key writes server-only fields as given.
  • The admin form shows the field as read-only, and the collection table does not offer an inline edit.
  • Property routes for the field (PUT .../{id}/total, deletes, uploads, increments and decrements) are refused with 403 for everyone, admins included.
  • Over MCP, describe_collection lists the field among those the site sets itself, for every caller.
  • Like protected, it counts as a field the site sets: registration strips it, and a non-admin cannot clone or import into the collection.
  • A server-only property cannot be required. Other writers have the value dropped before validation, so each of their saves would fail. tcms schema:lint reports this, and reports a serverOnly value that is not true or false.
  • serverOnly is honored on top-level properties only.

If you want to allow empty values for a required field, explicitly set:

Allow empty strings (for required fields):

{
"minLength": 0
}

Allow empty arrays (for required fields):

{
"minItems": 0
}

Example - Optional notes on a required field:

{
"notes": {
"type": "string",
"field": "textarea",
"label": "Additional Notes",
"minLength": 0,
"maxLength": 500
}
}

When validation fails, Total CMS will display clear error messages to users:

  • minLength/maxLength: “String must be at least X characters” or “String exceeds maximum length of X”
  • minimum/maximum: “Value must be at least X” or “Value must not exceed X”
  • pattern: “Value does not match required format”
  • enum: “Value must be one of: X, Y, Z”
  • minItems/maxItems: “Array must contain at least X items” or “Array exceeds maximum of X items”
  1. Be specific: Use validation to enforce your data requirements clearly
  2. Provide context: Use help text to explain validation requirements to users
  3. Balance strictness: Don’t over-validate - allow reasonable flexibility
  4. Test thoroughly: Verify validation works as expected in the admin interface
  5. Consider UX: Validation should help users, not frustrate them
{
"email": {
"$ref": "https://www.totalcms.co/schemas/properties/email.json",
"label": "Email Address",
"maxLength": 255
}
}
{
"phone": {
"$ref": "https://www.totalcms.co/schemas/properties/phone.json",
"label": "Phone Number",
"pattern": "^\\d{3}-\\d{3}-\\d{4}$"
}
}
{
"zipcode": {
"type": "string",
"field": "text",
"label": "ZIP Code",
"pattern": "^\\d{5}(-\\d{4})?$"
}
}
{
"completion": {
"type": "integer",
"field": "range",
"label": "Completion %",
"minimum": 0,
"maximum": 100
}
}
{
"gallery": {
"$ref": "https://www.totalcms.co/schemas/properties/gallery.json",
"label": "Product Images",
"minItems": 3,
"maxItems": 20
}
}
{
"username": {
"type": "string",
"field": "text",
"label": "Username",
"unique": true,
"minLength": 3,
"maxLength": 20,
"pattern": "^[a-z0-9_-]+$"
}
}
{
"email": {
"$ref": "https://www.totalcms.co/schemas/properties/email.json",
"label": "Email Address",
"unique": true,
"maxLength": 255
}
}

For complete JSON Schema documentation, see: