When you are creating your list of dicts your inner value of {4691} is actually a set not a dict.
https://realpython.com/python-sets/
Try this instead:
list_of_dicts = [{'f_note':'text','record_id': 4691},{'f_note':'sample','record_id': 4692}]
return jsonify(list_of_dicts)
See the error you encountered isolated
import json
test = {5565}
json.dumps(test)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\p\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\p\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\p\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\p\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type set is not JSON serializable
To keep the set functionaility you can cast it back to a list
remove_duplicates = [{**l[0], 'record_id': list(set([x['record_id'] for x in l]))} if len(l:=list(v)) > 1 else l[0] for _, v in groupby(sorted(list_of_dict, key=func), key=func)]