#Possible to set validator to accept record OR null ?

3 messages · Page 1 of 1 (latest)

leaden cargo
#

Possible to set validator to accept record OR null ?

old wharfBOT
#

Hi @leaden cargo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, it is possible to set a validator to accept a record or null in Convex. You can use the v.union function to create a validator that accepts multiple types. Here's an example:

v.union(v.record(v.string(), v.boolean()), v.null())

In this example, the validator will accept either a record with string keys and boolean values, or a null value.

Please note that the v.record function is used to describe objects that map arbitrary keys to values. The v.null function is used to validate null values. The v.union function is used to create a validator that accepts values that can be validated by any of its argument validators.

For more information, you can refer to the Convex documentation on Validators (https://docs.convex.dev/api/modules/values#validatorjson) and Record objects (https://docs.convex.dev/database/schemas#record-objects).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: