def convert_runsummary_to_json(
        df, comment='Uploaded via km3pipe.StreamDS', prefix='TEST_'
):
    """Convert a Pandas DataFrame with runsummary to JSON for DB upload"""
    data_field = []
    comment += ", by {}".format(getpass.getuser())
    for det_id, det_data in df.groupby('det_id'):
        runs_field = []
        data_field.append({"DetectorId": det_id, "Runs": runs_field})

        for run, run_data in det_data.groupby('run'):
            parameters_field = []
            runs_field.append({
                "Run": int(run),
                "Parameters": parameters_field
            })

            parameter_dict = {}
            for row in run_data.itertuples():
                for parameter_name in run_data.columns:
                    if parameter_name in REQUIRED_COLUMNS:
                        continue

                    if parameter_name not in parameter_dict:
                        entry = {'Name': prefix + parameter_name, 'Data': []}
                        parameter_dict[parameter_name] = entry
                    data_value = getattr(row, parameter_name)
                    try:
                        data_value = float(data_value)
                    except ValueError as e:
                        log.critical("Data values has to be floats!")
                        raise ValueError(e)
                    value = {'S': str(getattr(row, 'source')), 'D': data_value}
                    parameter_dict[parameter_name]['Data'].append(value)
            for parameter_data in parameter_dict.values():
                parameters_field.append(parameter_data)
    data_to_upload = {"Comment": comment, "Data": data_field}
    file_data_to_upload = json.dumps(data_to_upload)
    return file_data_to_upload