I have uploaded a *.mat file that contains a 'struct' to my jupyter lab using:
from pymatreader import read_mat
data = read_mat(mat_file)
Now I have a multi-dimensional dictionary, for example:
data['Forces']['Ss1']['flap'].keys()
Gives the output:
dict_keys(['lf', 'rf', 'lh', 'rh'])
I want to convert this into a JSON file, exactly by the keys that already exist, without manually do so because I want to perform it to many *.mat files with various key numbers.
EDIT: Unfortunately, I no longer have access to MATLAB. An example for desired output would look something like this:
json_format = {
"Forces": {
  "Ss1": {
    "flap": {
      "lf": [1,2,3,4],
      "rf": [4,5,6,7],
      "lh": [23 ,5,6,654,4],
      "rh": [4 ,34 ,35, 56, 66]
        }
      }
    }
  }
ANOTHER EDIT: So after making lists of the subkeys (I won't elaborate on it), I did this:
FORCES = []
for ind in individuals:
  for force in forces:
    for wing in wings:
      FORCES.append({
          ind: {
              force: {
                  wing: data['Forces'][ind][force][wing].tolist()
 
              }
          }
      })
Then, to save:
with open(f'{ROOT_PATH}/Forces.json', 'w') as f:
    json.dump(FORCES, f)
That worked but only because I looked manually for all of the keys... Also, for some reason, I have squared brackets at the beginning and at the end of this json file.
 
     
    