Skip to content

Key

  • Key(reference: str, rule=None, mandatory: bool = True)

Validates an array key.

test_dict = {
    'foo': 'bar'
}
v.key('foo').validate(test_dict)  # true

You can also validate the key value itself:

v.key('foo', v.equals('bar')).validate(test_dict)  # true

Third parameter makes the key presence optional:

v.key('lorem', v.stringType()).validate(test_dict)  # false
v.key('lorem', v.stringType(), False).validate(test_dict)  # true

The name of this validator is automatically set to the key name.

Categorization

  • Arrays
  • Nesting
  • Structures

Changelog

Version Description
1.0.0 Created

See also: