JSON Schema, if properly used, can replace data sanitisation.It doesn’t replace other API security considerations. Please note: To use Ajv with draft-06 schemas you need to explicitly add the meta-schema to the validator instance: Ajv generates code using do T templates to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
Async functions are supported in 7 and all modern browsers.
You can also supply any other transpiler as a function via property (if the schema is asynchronous), so you can differentiate these functions if you are using both synchronous and asynchronous schemas.
Validation result will be a promise that resolves with validated data or rejects with an exception See Options.
You can structure your validation logic across multiple schema files and have schemas reference each other using reference is supported in the keywords: const, enum, format, maximum/minimum, exclusive Maximum / exclusive Minimum, max Length / min Length, max Items / min Items, max Properties / min Properties, format Maximum / format Minimum, format Exclusive Maximum / format Exclusive Minimum, multiple Of, pattern, required, unique Items.
The value of “$data” should be a JSON-pointer to the data (the root is always the top level data object, even if the $data reference is inside a referenced subschema) or a relative JSON-pointer (it is relative to the current point in data; if the $data reference is inside a referenced subschema it cannot point to the data outside of the root level for this subschema). This schema requires that the value in property to point to other schemas previously added to the Ajv instance or to the fragments of the current schema.