Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  169] [ 2]  / answers: 1 / hits: 15148  / 9 Years ago, tue, july 28, 2015, 12:00:00

I'm using Joi to validate a JavaScript object in the server. The schema is like the following:



var schema = Joi.object().keys({
displayName: Joi.string().required(),
email: Joi.string().email(),
enabled: Joi.boolean().default(false, Default as disabled)
}).unknown(false);


The schema above will report an error if there is an unknown key in the object, which is expected, but what I want is to strip all the unknown silently, without an error. Is it possible to be done?


More From » node.js

 Answers
10

You need to use the stripUnknown option if you want to strip the unknown keys from the objects that you are validating.



cf options on https://github.com/hapijs/joi/blob/master/API.md#validatevalue-schema-options-callback


[#65643] Sunday, July 26, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
margaritakristinak

Total Points: 502
Total Questions: 127
Total Answers: 98

Location: England
Member since Mon, May 17, 2021
3 Years ago
;