Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

324
Views
Joi default value for empty array

I am struggling with the syntax for providing a default value to an empty and/or missing array key.

Joi.object({
    items: Joi.array().empty([]).items(Joi.number()).default([42]),
})

{ 
    items: []
}
or
{
}

In both cases I would want the default value of [42] to be substituted into the object. I'm assuming that I have to indicate that an empty array is invalid in some way, but I'm not sure how. I have also tried setting min(1) on items, but that doesn't work either (it flags the object as invalid, but does not substitute the default value).

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sorry, posted this too soon. This works:

Joi.object({
    items: Joi.array().optional().empty(Joi.array().length(0)).default([42]),
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!