Our great sponsors
-
ajv
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
Since this is a bit of a long post with multiple files I've provided a sample repo so you can see the final code in action, in case the post gets a bit too hard to follow.
A library called ajv offers schema validation, which allows you to validate data based on some pre-defined schema. This schema looks like this:
Now that cool thing we wanted to do? This library does exactly that!
Another cool alternative that allows for more powerful definitions (at the cost of losing clean interfaces) is typebox.