Skip to main content
Version: 1.3.4

Nested Key

You can validate deeply nested object properties using dot notation. For example, to validate the name property inside the profile object which is nested within user, you would use user.profile.name.

Example

Request Body

{
"user": {
"profile": {
"name": "John Doe",
"age": 30
}
}
}

Validation Rule

const rules = [
{
key: "user.profile.name",
type: "string",
required: true,
min: 3,
max: 50,
}
];

Explanation

  • key: "user.profile.name" specifies the deeply nested property in the request body to be validated using dot notation.

  • type: "string" indicates that the value of user.profile.name should be a string.

  • required: true means that the user.profile.name property is mandatory.

  • min: 3 specifies that the minimum length of the name string should be 3 characters.

  • max: 50 specifies that the maximum length of the name string should be 50 characters.