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": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "number" }
}
}
{ "name": "John Doe", "age": 21 }
[
// ...
{
"valid": true,
"keywordLocation": "/properties",
"instanceLocation": "",
"annotation": [ "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" }
[
// ...
{
"valid": true,
"keywordLocation": "/properties",
"instanceLocation": "",
"annotation": []
},
// ...
]
{ "foo": "foo", "bar": "bar" }
{ "foo": "foo", "baz": "baz" }
[
// ...
{
"valid": true,
"keywordLocation": "/properties",
"instanceLocation": "",
"annotation": [ "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" ]
}
[
// ...
{
"valid": true,
"keywordLocation": "/properties",
"instanceLocation": "",
"annotation": [ "name" ]
},
{
"valid": true,
"keywordLocation": "/patternProperties",
"instanceLocation": "",
"annotation": [ "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"
}
[
// ...
{
"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
orpatternProperties
are evaluated againstadditionalProperties
.