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.

Kind Applicator Annotation
Applies To Object
Dialect 2020-12
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
Also see

Annotations

The annotation result of this keyword is the set of instance property names matched by this keyword.

Explanation

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.

  • The value of properties must be an object.
  • Each property value of this object must be a valid JSON Schema.
  • Each key within properties represents a property name in the object instance.
  • Omitting this keyword has the same assertion behavior as an empty object.
Schema with 'properties' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "number" }
  }
}
An object instance with properties conforming to the schema is valid Instance
{ "name": "John Doe", "age": 21 }
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/properties",
    "instanceLocation": "",
    "annotation": [ "name", "age" ]
  },
  // ...
]
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
  }
}
An instance with no defined property is valid Instance
{ "baz": "baz" }
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/properties",
    "instanceLocation": "",
    "annotation": []
  },
// ...
]
An instance with 'false' property is invalid Instance
{ "foo": "foo", "bar": "bar" }
An instance with 'true' property and additional properties is valid Instance
{ "foo": "foo", "baz": "baz" }
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/properties",
    "instanceLocation": "",
    "annotation": [ "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" }
  }
}
An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": "foo@bar.com"
}
The value of 'Age' must be a number Instance
{
  "name": "John Doe",
  "Age": "21",
  "email": "foo@bar.com"
}
An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": [ "foo", "@", "bar", "com" ]
}
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/properties",
    "instanceLocation": "",
    "annotation": [ "name" ]
  },
  {
    "valid": true,
    "keywordLocation": "/patternProperties",
    "instanceLocation": "",
    "annotation": [ "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
}
The value of the 'name' property must be a string Instance
{
  "name": [ "John", "Doe" ],
  "Age": 21,
  "email": "foo@bar.com"
}
An object instance with properties conforming to the schema is valid Instance
{
  "name": "John Doe",
  "Age": 21,
  "email": "foo@bar.com"
}
Annotations
[
  // ...
  {
    "valid": true,
    "keywordLocation": "/properties",
    "instanceLocation": "",
    "annotation": [ "name" ]
  },
  {
    "valid": true,
    "keywordLocation": "/patternProperties",
    "instanceLocation": "",
    "annotation": [ "Age" ]
  },
  {
    "valid": true,
    "keywordLocation": "/additionalProperties",
    "instanceLocation": "",
    "annotation": [ "email" ]
  },
  // ...
]
  • Property names not present in properties or patternProperties are evaluated against additionalProperties.