Skip to main content
JSON Forms supports both JSON Schema Draft 4 and Draft 7. The main JsonSchema type is a union of both versions.

JsonSchema

Union type for JSON Schema Draft 4 and Draft 7.
JsonSchema
JsonSchema4 | JsonSchema7
Main type that accepts either JSON Schema Draft 4 or Draft 7 schemas.

JsonSchema7

JSON Schema Draft 7 specification interface.

Schema metadata

$id
string
Schema identifier. Tells references where the root of the document is located.
$schema
string
Meta-schema URL. Recommended to include in the root of any JSON Schema.
$ref
string
Reference to another schema or schema definition.
title
string
Human-readable title of the schema.
description
string
Detailed description of the schema.
default
any
Default value for the data represented by this schema.

Type definition

type
string | string[]
The basic type of this schema. Can be one of: string, number, integer, object, array, boolean, null, or an array of these types.
enum
any[]
Enumerates the allowed values for this schema.
{
  "type": "string",
  "enum": ["red", "green", "blue"]
}
const
any
Specifies a single constant value that the data must match.

Number validation

multipleOf
number
The value must be a multiple of this number (e.g., 10 is a multiple of 5).
maximum
number
Maximum value allowed (inclusive).
exclusiveMaximum
number
Maximum value allowed (exclusive). Value must be less than this number.
minimum
number
Minimum value allowed (inclusive).
exclusiveMinimum
number
Minimum value allowed (exclusive). Value must be greater than this number.

String validation

maxLength
number
Maximum length of the string.
minLength
number
Minimum length of the string.
pattern
string
Regular expression pattern that the string must match.
format
string
String format identifier (e.g., date, time, date-time, email, uri).

Array validation

items
JsonSchema7 | JsonSchema7[]
Schema for array items. Can be a single schema or an array of schemas for tuple validation.
additionalItems
boolean | JsonSchema7
Schema for additional items beyond those defined in items array.
maxItems
number
Maximum number of items in the array.
minItems
number
Minimum number of items in the array.
uniqueItems
boolean
Whether all items in the array must be unique.
contains
JsonSchema7
Schema that at least one array item must match.

Object validation

properties
{ [property: string]: JsonSchema7 }
Map of property names to their schemas.
patternProperties
{ [pattern: string]: JsonSchema7 }
Map of regex patterns to schemas. Properties matching the pattern must validate against the schema.
additionalProperties
boolean | JsonSchema7
Schema for properties not defined in properties or patternProperties. If false, no additional properties are allowed.
required
string[]
Array of property names that must be present.
propertyNames
JsonSchema7
Schema that all property names must match.
maxProperties
number
Maximum number of properties allowed.
minProperties
number
Minimum number of properties required.
dependencies
{ [key: string]: JsonSchema7 | string[] }
Defines dependencies between properties. Value can be an array of required property names or a schema that must validate when the key property is present.

Schema composition

allOf
JsonSchema7[]
Data must validate against all of the schemas in this array.
anyOf
JsonSchema7[]
Data must validate against at least one of the schemas in this array.
oneOf
JsonSchema7[]
Data must validate against exactly one of the schemas in this array.
not
JsonSchema7
Data must not validate against this schema.

Conditional schemas

if
JsonSchema7
Conditional schema. If data validates against this schema, apply the then schema.
then
JsonSchema7
Schema to apply if the if condition is true.
else
JsonSchema7
Schema to apply if the if condition is false.

Schema reuse

definitions
{ [key: string]: JsonSchema7 }
Container for reusable schema definitions. Reference with $ref.
{
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" }
      }
    }
  },
  "type": "object",
  "properties": {
    "billingAddress": { "$ref": "#/definitions/address" }
  }
}

Additional properties

readOnly
boolean
Indicates the value should not be modified.
writeOnly
boolean
Indicates the value may be set but should not be retrieved.
examples
any[]
Array of example values for documentation.
errorMessage
any
Custom error message for validation failures.

JsonSchema4

JSON Schema Draft 4 specification interface. Similar to Draft 7 with key differences:

Key differences from Draft 7

  • Uses id instead of $id for schema identifier
  • exclusiveMaximum and exclusiveMinimum are boolean instead of number
  • Does not support: const, contains, propertyNames, if/then/else, readOnly, writeOnly, examples
Most JSON Forms projects use JSON Schema Draft 7. Draft 4 support is maintained for backward compatibility.

Usage example

import { JsonSchema } from '@jsonforms/core';

const schema: JsonSchema = {
  type: 'object',
  properties: {
    name: {
      type: 'string',
      minLength: 3,
      description: 'User name'
    },
    age: {
      type: 'integer',
      minimum: 0,
      maximum: 120
    },
    email: {
      type: 'string',
      format: 'email'
    },
    role: {
      type: 'string',
      enum: ['admin', 'user', 'guest']
    }
  },
  required: ['name', 'email']
};

Build docs developers (and LLMs) love