[Python] open a .json file with multiple dictionaries

Discussão em 'Python' iniciado por Stack, Março 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem that I can't solve with python, it is probably very stupid but I didn't manage to find the solution by myself.

    I have a .json file where the results of a simulation are stored. The result is stored as a series of dictionaries like

    {"F_t_in_max": 709.1800264942982, "F_t_out_max": 3333.1574129603068, "P_elec_max": 0.87088836042046958, "beta_max": 0.38091242406098391, "r0_max": 187.55175182942901, "r1_max": 1354.8636763521174, " speed ": 8}
    {"F_t_in_max": 525.61428305710433, "F_t_out_max": 2965.0538075438467, "P_elec_max": 0.80977406754203796, "beta_max": 0.59471606595464666, "r0_max": 241.25371753877008, "r1_max": 688.61786996066826, " speed ": 9}
    {"F_t_in_max": 453.71124051199763, "F_t_out_max": 2630.1763649193008, "P_elec_max": 0.64268078173342935, "beta_max": 1.0352896471221695, "r0_max": 249.32706230502498, "r1_max": 709.11415981343885, " speed ": 10}


    I would like to open the file and and access the values like to plot "r0_max" as function of "speed" but I can't open unless there is only one dictionary. I use

    with open('./results/rigid_wing_opt.json') as data_file:
    data = json.load(data_file)


    but When the file contains more than one dictionary I get the error

    ValueError: Extra data: line 5 column 1 - line 6 column 1 (char 217 - 431)

    Continue reading...

Compartilhe esta Página