import json class JsonDictWithDuplicateKeys(dict): """A specialized JSON dict with duplicate keys support. """ def __init__(self, items): # `json.dumps()` will check the underlying dict (`self` in our case) and outputs # directly if it is empty. So we need to have something in the dictionary. self[''] = '' self._items = items def items(self): return self._items b = '{"dps":{"1630064726":5.0,"1630064726":3.0,"1630064726":6.0}}' j = json.loads(b, object_pairs_hook=JsonDictWithDuplicateKeys) print(json.dumps(j, indent=4, sort_keys=True))