Код: Выделить всё
{
"parent1": {
"child1": "bob"
},
"parent1": {
"child2": "tom"
},
"parent2": {
"child1": "jon"
}
}
Код: Выделить всё
{
"parent1": {
"child1": "bob",
"child2": "tom"
},
"parent2": {
"child1": "jon"
}
}
Код: Выделить всё
import json
def check_duplicates(pairs):
d = {}
for key, val in pairs:
if key in d:
raise ValueError(f"Duplicate key(s) found: {key}")
else:
d[key] = val
return d
filename = "test.json"
with open(filename, "r") as f:
try:
data = json.load(f, object_pairs_hook=check_duplicates)
except ValueError as err:
print(f"{filename}: Failed to decode: {err}")
Подробнее здесь: https://stackoverflow.com/questions/786 ... icate-keys