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
How to forbid a key from object

Seems like a no brainer but I can't figure how to add a constraint to forbid the existence of a key in Joi, please how do I do this.

    const data = {foo: 'xyz', bar: '123'};
    const schema = {
        foo: Joi.string(),
        // how do i forbid bar
        bar: Joi.forbid()
    };
    
    const { error } = Joi.object(schema).validate(data)

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

0

Use forbidden: https://joi.dev/api/?v=17.4.2#anyforbidden

const schema = {
    a: Joi.any().forbidden()
};
about 4 years ago · Juan Pablo Isaza Report

0

you can simple delete the key from the object :

1st Method : delete data.bar

2nd method : {bar,...schema}=data

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!