How to use schema models
Implementing a schema model based on a JSON scheme
Betty Blocks avatar
Written by Betty Blocks
Updated over a week ago

After reading this article, you'll know:

  • What a schema model is

  • How to ensure you use valid JSON for a schema model

  • How to use a schema model in your application

What's a schema model?

A schema model is a model that can contain multiple values. It isn't configurable like your normal models are. They can be seen as an extension of them though. How come you might ask? Well, we can use the properties defined in the schema models as objects within regular models. This is very useful because in the schema model, we can set multiple values for a property, so when we use the schema model in a regular model we can also set multiple values. This allows you to save for example the answers from a questionnaire more easily.

How does it work

When you create a new model you have three options, to create a schema model simply select the schema model tab. Give the schema model a proper name and now the most important part, give the schema model a valid JSON schema. You can verify if your JSON schema is valid by using a validator like this one.

When we create the schema model, it'll be turned into a structured model that we can put to use in a regular model, let's check out how this work.

Using the schema model

If you create a new model or navigate to an existing one, you can see that there's a property type called 'object'. This is the property type needed to use the values from the schema model. You can see your schema model in the dropdown list for structured models. After you select it you can define which values you want this property to have.

What makes the object property so powerful is that it can save entire objects making it able to save multiple values as you can see in the image below. You can save the answer + a score that's attached to the answer. In this example, there are just two values but you can create more if you'd like to.

You can now use this in, for example, your page builder to create a dynamic questionnaire.



"description":"This schema includes an object property schema for the questionnaire to create answers and scoring",

"properties":{"answer":{"type":"string"}, "score":{"type":"number"}},

"title":"Questionnaire", "type":"object"

An example of the schema model used in this article.

Did this answer your question?