joi icon indicating copy to clipboard operation
joi copied to clipboard

how to unset a string field when it's an empty string

Open liudaoping opened this issue 3 years ago • 1 comments

For example, b is empty string filed

{ 
  a: 'a',
  b: ''
}

after validating , convert to an object which filed b is deleted

{
  a: 'a'
}

liudaoping avatar May 30 '21 06:05 liudaoping

you can use joi.string().empty('') which will treat empty string the same as properties with undefined values.

see: https://joi.dev/api/?v=17.4.2#anyemptyschema

Kanosakl avatar Sep 25 '21 04:09 Kanosakl