0

I would like to convert/transform into an empty array if the value is null but when I add the custom method of Joi on my list schema, it doesn't seem to pass by and the value is never converted. I'll always receive null :

Joi.list().allow(null).custom((value) => {
                if (value === null) {
                    return [];
                }

                return value;
            });
Joi.list().allow(null).custom((value) => {
                if (value === null) {
                    return [];
                }

                return [];
            });

Both examples above doesn't work

If value === null, convert to []

Else do nothing

Thanks for your help !

  • Your syntax may be wrong. This might help: https://stackoverflow.com/questions/41470251/joi-allow-null-values-in-array – AndreFeijo Jul 04 '22 at 09:46
  • @AndreFeijo I do not have any problem with `null`, but I would like to convert it into an empty array when I get `null` as value. –  Jul 04 '22 at 09:49
  • @AndreFeijo the `custom` method is never read and so, `null` will never be transformed to anything else and I don't understand why `custom` doesn't work here.. –  Jul 04 '22 at 09:50

0 Answers0