Using JsonSchema to validate inside a Realm webhook function

I’m just wondering if it’s possible to use the existing JsonSchema in any way within a Realm webhook function. What I’m thinking of is to a way validate the payload body, and since we already have all of the things we need within the JsonSchema which is being used as a validator for the collection, I wondered if there is a way to use that.

Two things came to mind, the first is just trying to insert the data into the collection and catching any validation errors. The second is whether I can duplicate the schema itself within the function and use a JsonSchema library to validate.

Just wondering if there’s an easier way than those two, especially if I’m not ready to insert the data into the collection at that point, but just want to validate it without duplicating code?

Any help is much appreciated!