ich möchte Einträge aus einer JSON Datei filtern, aber leider habe ich dabei Probleme.
So sieht ein Ausschnitt aus meiner "Beispiel" JSON Datei aus:
Code: Alles auswählen
[{
'Name': 'Otto',
'Birthday': '1990-02-01'
},
{
'Name': 'Susanne',
'Birthday': None
}]
Mein erster Versuch sah so aus:
Code: Alles auswählen
import json
with open("Beispiel.json", mode="r", encoding="utf8") as file:
people = json.load(file)
birth = []
for entry in people:
if int(entry['Birthday'][0:3]) >= 1990:
birth.append(entry)
Code: Alles auswählen
birth = []
for entry in people:
if entry['Birthday'] == None:
entry['Birthday'] = 0
elif int(entry['Birthday][0:3]) >= 1990:
birth.append(entry)
else:
continue