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

166
Views
Joi validator body accepts object or array

I would like to use Joi to validate an object or an array of objects.

I have tried doing this but it looks like it's checking for both an Array of entities and entity. I would like it to only check one or the other. entity is also a joi object.

Joi.alternatives().try(Joi.array().items(entity), entity)

For example, I want both of these bodies to be validated

  1. array of entities
    [
    {name: "joe"},
    {name: "tim"},
    {name: "bob"}
    ]
  1. single entity
    {name: "joe"}

What's the best way to do this?

about 4 years ago · Juan Pablo Isaza
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!