properties : Object<String, Schema>

properties

Object<String, Schema>

Validation succeeds if, for each name that appears in both the instance and as a name within this keyword’s value, the child instance for that name successfully validates against the corresponding schema.

Value This keyword must be set to an object where each value is a valid JSON Schema
Kind Applicator Annotation
Applies To Object
Dialect 2020-12
Changed In None
Introduced In Draft 1
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.3.2.1
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/properties.json
Default {}
Annotation Array The set of instance property names validated by this keyword's subschema
Affected By None
Affects
Also See

The properties keyword is used to define the properties (keys) that an object instance must or may contain. It allows you to specify the expected value of a property in an object instance. Each property within the properties object is defined by its name and a subschema describing the value expected for that property if present.

The annotation result of this keyword is the set of instance property names matched by this keyword. This annotation affects the behavior of additionalProperties and unevaluatedProperties.

  • Each key within properties represents a property name in the object instance.
Schema with 'properties' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "number" }
  }
}
Valid An object instance with properties conforming to the schema is valid Instance
{ "name": "John Doe", "age": 21 }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "name", "age" ] }
Invalid An object instance with properties not conforming to the schema is invalid Instance
{ "name": "John Doe", "age": "21" }
  • Annotations are not produced when validation fails.
Schema with properties (keys) set to boolean values Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "foo": true,
    "bar": false
  }
}
Valid An instance with no defined property is valid Instance
{ "baz": "baz" }
Annotations
{ "keyword": "/properties", "instance": "", "value": [] }
Invalid An instance with 'false' property is invalid Instance
{ "foo": "foo", "bar": "bar" }
Valid An instance with 'true' property and additional properties is valid Instance
{ "foo": "foo", "baz": "baz" }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "foo" ] }
Schema with no 'additionalProperties' defined Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" }
  },
  "patternProperties": {
    "[Aa]ge$": { "type": "number" }
  }
}
Valid An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": "foo@bar.com"
}
Invalid The value of 'Age' must be a number Instance
{
  "name": "John Doe",
  "Age": "21",
  "email": "foo@bar.com"
}
Valid An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": [ "foo", "@", "bar", "com" ]
}
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "name" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "Age" ] }
  • If you don’t define a property using properties or patternProperties, but don’t disallow it with additionalProperties, it would still be valid with any value.
Schema with 'properties', 'patternProperties' and 'additionalProperties' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" }
  },
  "patternProperties": {
    "[Aa]ge$": { "type": "number" }
  },
  "additionalProperties": true
}
Invalid The value of the 'name' property must be a string Instance
{
  "name": [ "John", "Doe" ],
  "Age": 21,
  "email": "foo@bar.com"
}
Valid An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": "foo@bar.com"
}
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "name" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "Age" ] }
{ "keyword": "/additionalProperties", "instance": "", "value": [ "email" ] }
  • Property names not present in properties or patternProperties are evaluated against additionalProperties.