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": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
}
}
{ "name": "John Doe", "age": 21 }
{ "keyword": "/properties", "instance": "", "value": [ "name", "age" ] }
{ "name": "John Doe", "age": "21" }
- Annotations are not produced when validation fails.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"foo": true,
"bar": false
}
}
{ "baz": "baz" }
{ "keyword": "/properties", "instance": "", "value": [] }
{ "foo": "foo", "bar": "bar" }
{ "foo": "foo", "baz": "baz" }
{ "keyword": "/properties", "instance": "", "value": [ "foo" ] }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"patternProperties": {
"[Aa]ge$": { "type": "number" }
}
}
{
"name": "John Doe",
"Age": 21,
"email": "foo@bar.com"
}
{
"name": "John Doe",
"Age": "21",
"email": "foo@bar.com"
}
{
"name": "John Doe",
"Age": 21,
"email": [ "foo", "@", "bar", "com" ]
}
{ "keyword": "/properties", "instance": "", "value": [ "name" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "Age" ] }
- If you don’t define a property using
properties
orpatternProperties
, but don’t disallow it withadditionalProperties
, it would still be valid with any value.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" }
},
"patternProperties": {
"[Aa]ge$": { "type": "number" }
},
"additionalProperties": true
}
{
"name": [ "John", "Doe" ],
"Age": 21,
"email": "foo@bar.com"
}
{
"name": "John Doe",
"Age": 21,
"email": "foo@bar.com"
}
{ "keyword": "/properties", "instance": "", "value": [ "name" ] }
{ "keyword": "/patternProperties", "instance": "", "value": [ "Age" ] }
{ "keyword": "/additionalProperties", "instance": "", "value": [ "email" ] }
- Property names not present in
properties
orpatternProperties
are evaluated againstadditionalProperties
.