Validate JSON by Schema before save

HiI

I was wondering whether there is any way for me to specify a JSON schema against which my users’ entries can be checked before they are committed into the database.

We have some JSON fields for structured data entry, where it seemed overkill to set up a complex recursive component structure.
However, now I have the problem that sometimes a typo slips into the json keys or values that should contain only valid URLs are filled with unexpected strings. As a result, the consuming app wouldn’t be able to make sense of those entries.

I know there exists JSON schema that would let me specify exactly what I want.
Is anything like this hidden in strapi or on the development roadmap, similarly to how I can, for example, specify regex validation for my text fields?

System Information
  • Strapi Version: 3.6.2
  • Operating System: Docker
  • Database: PostgreSQL 12
  • Node Version: 14.15.0
  • NPM Version: 7.9.0

Hi @Alex_B, built into Strapi, no. But you could use yup to build validations for your data and maybe in the process provide feedback based on what the validation returns. This would require you to customize your controllers, however.

Hey Richard,

alright, thanks for the suggestion, will see what I can accomplish.
Would you know of any implementation examples I can look at for this specific usecase?

Hey Alex,
I’m sorry, unfortunately I don’t know of any precreated example implementations for this.