propertyNames : Schema

propertyNames

Schema

Validation succeeds if the schema validates against every property name in the instance.

Value This keyword must be set to a valid JSON Schema
Kind Applicator
Applies To Object
Dialect 2020-12
Changed In None
Introduced In Draft 6
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.3.2.4
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/propertyNames.json
Default {}
Annotation None
Affected By None
Affects None
Also See

The propertyNames keyword in is used to define constraints on the property names within an object instance. It allows you to specify a schema that all the property names in an object instance must adhere to.

Examples

Schema with 'propertyNames' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "propertyNames": { "maxLength": 3 }
}
Valid An object instance with the length of property names less than or equal to 3 is valid Instance
{ "foo": "foo", "bar": 33 }
Invalid The length of any property name must not be greater than 3 Instance
{ "name": "John Doe", "age": 21 }
Schema with 'propertyNames' set to true Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "propertyNames": true
}
Valid An object instance with any property name is valid Instance
{ "foo": "bar" }
Valid An instance with an array is valid Instance
[ "no", "effect" ]
  • propertyNames has no effect on instances other than objects.
Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "propertyNames": { "type": "number" }
}
Invalid An object instance with any property is invalid Instance
{ "foo": 22 }
Valid An empty object is valid Instance
{}
  • The property names in any object instance cannot be a number. Therefore, any object instance will fail against the above schema, except for an empty object.