Use default renderer when given schemata is missing data properties

I am working on an interesting project that involves utilizing arbitrary/unknown json data input that will be translated into visual forms.

I was wondering if it was possible to have the uischema/schema fallback to the default renderer in the event that a uischema or a schema does exist, but there is data available that is not defined in the provided schemata.

I have peeked at Generate Both Schemata Example - JSON Forms which is nice and works well. However the problem I’m trying to address is that a uischema/schema can optionally be created for some JSON data (if the default rendering is not desired). Once these are created in the JSON data contains any new data, that is no longer present in the existing shemata, it will not be visible through the forms.

What is the best way to essentially provide the default rendering capabilities and only override specific shemata elements that are defined in uischema/schema.

json data contains { “name”: “peter”, “age”: 20 }
schema/uischema created with the name/age properties of the json data

Later on “sex” is added to data through another data source (outside the form), and now it is not defined in schemata, causing the form to not render this new value.

This is where I would like the schemata defined to kick in for name/age and for any other potential property not defined fallback to the default.

Is this possible?

Thanks in advance!

Hi @syncthetic,

This is an interesting use case. In general I can see two options to tackle the issue:

  1. Handle it outside of JSON Forms: When you receive new external data which is not part of the already used JSON Schema and UI Schema, adapt the JSON Schema and UI Schema to include the new data. How straightforward this is depends on the JSON Schemas, UI Schemas and custom renderers you employ.
  2. Use custom renderer: You need a custom renderer whose responsibility is to identify data which is not part of the JSON Schema and UI Schema, generate those sub schemas locally and then dispatch back to JSON Forms using the generated sub schemas.
    A simple approach would be a custom type: object renderer which just shallowly checks the data and sub schemas and adds missing properties accordingly. However this only works if your UI schemas are designed in a way that all objects are represented by object controls and each object control is responsible for all properties of its object.
    Should you have more complicated UI Schema setups you accordingly need more and/or complex custom renderers.

In general I can see both approaches working. I don’t necessarily see the need for custom renderers here, so without knowing your exact requirements I would probably suggest to first evaluate the first approach. This would also help you in case you wanted to integrate with other JSON Schema based tools.
If you also have use cases like using patternProperties where you need a similar custom renderer anyway you could also look into that first.

Hi Stefan,

Thanks for your quick feedback. Additionally, I would also quickly say that from peeping on this forum thank you on behalf of the product and all other customers overall as you have clearly demonstrated excellent character with your responses and time to understand customer problems and offer solutions.

I will be taking your advise and potentially seeking out both of these options for implementation.

Thanks again!

1 Like