I have a custom manage.py command which I am using to upload a json file (a list of dictionaries) to my model. It appears to upload two records fine, but then throws a key error:
KeyError: 'headline'
My code is as follows:
class Command(BaseCommand):
def handle(self,*args,**options):
filename = '/DoJ_Data_01-12-18.json'
newpath = str(Path(home))+filename
with open(newpath) as json_file:
data = json.load(json_file)
for d in data:
q = doj(headline=d['headline'],topics=d['topics'],text=d['text'],url=d['url'],date=d['date'])
q.save()
As far as I can tell the json is valid. What am I missing?