I am trying to write a validation method for the following object ( associative array ):
{
"10:00": {
discount: 10,
time: "10:00",
},
"11:00": {
discount: 11,
time: "11:00",
},
...
....
}
Using Joi (https://github.com/hapijs/joi) What i got so far is this:
Joi.object().keys(
{time:{
discount: Joi.number(),
time: Joi.string(),
}}
),
which is obviously wrong and failing with : ValidationError: child "discounts" fails because ["10:00" is not allowed, "11:00" is not allowed]
can anyone suggest how to write validation for objects with variable number of keys ( associative array )