Change the data based on conditions without the middleware

Use case
I have a requirement, if name is equal to durian I want to change country dropdown’s value to the France. For the moment I am doing this with middleware like this

const middleware = useCallback((state, action, defaultReducer) => {
    const newState = defaultReducer(state, action);
    switch (action.type) {
      case INIT:
      case UPDATE_CORE:
      case UPDATE_DATA: {
        if (newState.data.name === 'durian') {
          newState.data.country = 'france';
        }
        return newState;
      }
      default:
        return newState;
    }
  }, []);

The problem with this approach is for each and every condition we need to add code in front end. We want to save this conditions to the backend in some form of json schema like this

{
  "data": {
    "name": "durian",
    "country": "france"
  }
}

Can we do this with JSON forms without a middleware?

Hi @pathum-kalhan ,

unfortunately there is no concept in JsonForms to automatically adapt values of other properties that can be described declaratively in the UI Schema or JSON Schema.
This is in fact one of the use cases that the middleware is supposed to solve.

IF you want to define these mappings in the backend, my suggestion is to design a custom datastructure (like you already briefly described) and then write a generic middleware implementation that derives its behavior from that.
With this, you can also define the replacements and conditions in the backend.

I hope that helps and best regards,
Lucas