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
Base 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 restricts properties of an object instance, when present, to match their corresponding subschemas definitions. Information about the properties that this keyword was evaluated for is reported using annotations.

Remember that JSON Schema is a constraint-driven language. Therefore, non-object instances successfully validate against this keyword. If needed, make use of the type keyword to constraint the accepted type accordingly.

Examples

A schema that constrains object instances to a string and integer property Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer" }
  }
}
Valid An object value that defines both declared properties and matches the corresponding schemas is valid Instance
{ "name": "John Doe", "age": 50 }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "name", "age" ] }
Valid An object value that defines one of the declared properties and matches the corresponding schema is valid Instance
{ "name": "John Doe" }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "name" ] }
Valid An empty object value is valid as properties are optional by default Instance
{}
Invalid An object value that defines both declared properties but does not match one of the corresponding schemas is invalid Instance
{ "name": "John Doe", "age": "this should have been an integer" }
Invalid An object value that defines one of the declared properties but does not match its corresponding schema is invalid Instance
{ "name": 999 }
Valid A non-object value is valid Instance
"Hello World"
A schema that constrains object instances to forbid a specific property Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "forbidden": false,
    "permitted": true
  }
}
Valid An object value that only defines the permitted property is valid Instance
{ "permitted": "anything is valid" }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "foo", "permitted" ] }
Valid An object value that defines any additional property is valid as additional properties are permitted by default Instance
{ "foo": "bar", "baz": 2 }
Annotations
{ "keyword": "/properties", "instance": "", "value": [ "foo", "baz" ] }
Invalid An object value that only defines the forbidden property is invalid Instance
{ "forbidden": 1 }
Invalid An object value that defines the forbidden property alongside other properties is invalid Instance
{ "forbidden": 1, "permitted": 2 }