Default Value not displaying

Hi @Dhruw,

Thanks for the kind words.

The “problem” with the default keyword in JSON Schema is that there is no associated semantic meaning to it, so any framework/library is free to handle it how they see it fit, e.g. when and how to set the value.

In JSON Forms itself we don’t have any special functionality implemented regarding the default properties. However internally we use AJV which offers some (limited) default functionality, i.e. it will set default values during the validation process in case they are undefined. See here for how to enable this functionality in JSON Forms.
Having said that, I think defaults within a oneOf construct like you defined are exactly one of the use cases which is not supported by AJV. The reason is because it is impossible for AJV to know which oneOf actually applies to your data.

However there is a way to accomplish your goal: You can implement a custom oneOf renderer in JSON Forms and then on tab change (or however the renderer visualizes the oneOf selection) you can just set the default value in the object.

Unrelated to the question at hand: Your JSON Schema is rather unconvential, in the sense of that all oneOf entries are exactly the same and just differ in the default value. Was this done to illustrate the problem or is that an actual schema you’re using? If it’s the latter then I would like to suggest to replace the whole oneOf with a simple enum containing three options.

1 Like