Conditionals in Schema

Hi,

I am new to JSONForms and wanted to make sure that I understand things correctly. My understanding is that JSONForms does not support conditionals (if, then, else…) in the Schema and that if you have something like that, you simply need to create a version of them in the UISchema instead. Is that correct?

Also, which draft of json schema should I ideally target?

Lastly, do you have any rough idea of when version 3 might be released. JSONForms looks promising for a couple of projects I am working on and one of the questions that is going to come up is which version to target.

Cheers,

Alex

Hi @AlexNeblett,

Thanks for your interest in JSON Forms.

I am new to JSONForms and wanted to make sure that I understand things correctly. My understanding is that JSONForms does not support conditionals (if, then, else…) in the Schema and that if you have something like that, you simply need to create a version of them in the UISchema instead. Is that correct?

If/Then/Else is partially supported in JSON Forms. If used only for validation purposes, e.g. to mark an attribute required conditionally, they usually work fine. However we ignore them when they are used for structure. Note that If/Then/Else in JSON Schema is very generic so this is not only about conditionally showing some inputs but it can basically change the whole schema.

There is no special If/Then/Else in the UI Schema. However we have support for rules in the UI Schema which can express conditional enablement and visibility for associated UI Schema elements. To express the conditions we again use JSON Schema, so technically you can then actually use If/Then/Else there.

Some of our renderer sets (i.e. React Material and Vue 2 Vuetify) also have renderers for oneOf/allOf/anyOf. So if you can reformulate your If/Then/Else construct to oneOf/allOf/anyOf you already get some basic support.

Note that you can always also add your own If/Then/Else support via custom renderers. So if you need to support it in some way you can also go this route. Usually this is rather straightforward as most people don’t need support for ALL use cases but just the ones they actually encounter in their schemas.

Also, which draft of json schema should I ideally target?

JSON Forms’ core functionality mostly covers Draft 7. However internally we use AJV for validating which supports everything up to the latest draft, so any later validation features can also be used. If you like to use advanced resolving features then we recommend to use a resolving library like json-refs and only handing over the resolved schema to JSON Forms.

Lastly, do you have any rough idea of when version 3 might be released. JSONForms looks promising for a couple of projects I am working on and one of the questions that is going to come up is which version to target.

Releasing JSON Forms v3 is our top priority right now. Note that this is not a complete rewrite nor does the API change a lot. It’s v3 because it could potentially break users, for example because we switched from Material UI v4 to v5 and now also release ESM modules targeting esnext. We have a migration guide which covers the most important aspects.

We regularly release prereleases, the current one is 3.0.0-beta.1. I would definitely recommend targeting this version and you can do so starting now. 30% of our user base is already migrated (according to npm download statistics).

There will be no new features until the release, only bug fixes. I can’t give any concrete dead line for the final release as our work load varies depending on the needs of our paying customers. Note however that in our Milestone planning almost nothing is left to do for 3.0 and mostly boils down to finish this PR.