'IndexError: list index out of range - JSON files

I'm try to extract the first element in the authors section of this json file

   content = json.load(files)
   if content['metadata']:
       firstname = content['metadata']['authors'][0]['first']
       firstname_list.append(firstname)

getting IndexError: list index out of range enter image description here

json format is:

{"paper_id": "000affa746a03f1fe4e3b3ef1a62fdfa9b9ac52a","metadata":{"title": "Correlation between antimicrobial consumption and incidence of health-care- associated infections due to methicillin- resistant Staphylococcus aureus and vancomycin-resistant enterococci at a university hospital in Taiwan from 2000 to 2010", "authors":[{"first": "Chih-Cheng", "middle": [], "last": "Lai", "suffix": "", "affiliation": {"laboratory": "", "institution": "Chi Mei Medical Center", "location": {"settlement": "Liouying, Tainan", "country": "Taiwan"}}, "email": ""},{"first": "Chen-Chen", "middle": [], "last": "Chu", "suffix": "", "affiliation": {"laboratory": "", "institution": "National Taiwan University Hospital", "location": {"settlement": "Taipei", "country": "Taiwan"}}, "email": ""}, {"first": "Aristine", "middle": [], "last": "Cheng", "suffix": "", "affiliation": {"laboratory": "", "institution": "New Taipei City", "location": {"country": "Taiwan"}}, "email": ""}, {"first": "Yu-Tsung", "middle": [], "last": "Huang", "suffix": "", "affiliation": {"laboratory": "", "institution": "New Taipei City", "location": {"country": "Taiwan"}}, "email": ""}, {"first": "Po-Ren", "middle": [], "last": "Hsueh", "suffix": "", "affiliation": {"laboratory": "", "institution": "National Taiwan University College of Medicine", "location": {"settlement": "Taipei", "country": "Taiwan"}}, "email": ""}]}, 
"abstract": .....



Solution 1:[1]

You didn't close the last Dictionary

Correct JSON file:

content = {
"paper_id": "000affa746a03f1fe4e3b3ef1a62fdfa9b9ac52a",
"metadata":
    {"title":
         "Crrelation between antimicrobial consumption and incidence of health-care- associated infections due to methicillin- resistant Staphylococcus aureus and vancomycin-resistant enterococci at a university hospital in Taiwan from 2000 to 2010",
         "authors":[
             {"first": "Chih-Cheng", "middle": [], "last": "Lai", "suffix": "", "affiliation": {"laboratory": "", "institution": "Chi Mei Medical Center", "location": {"settlement": "Liouying, Tainan", "country": "Taiwan"}}, "email": ""},
             {"first": "Chen-Chen", "middle": [], "last": "Chu", "suffix": "", "affiliation": {"laboratory": "", "institution": "National Taiwan University Hospital", "location": {"settlement": "Taipei", "country": "Taiwan"}}, "email": ""},
             {"first": "Aristine", "middle": [], "last": "Cheng", "suffix": "", "affiliation": {"laboratory": "", "institution": "New Taipei City", "location": {"country": "Taiwan"}}, "email": ""},
             {"first": "Yu-Tsung", "middle": [], "last": "Huang", "suffix": "", "affiliation": {"laboratory": "", "institution": "New Taipei City", "location": {"country": "Taiwan"}}, "email": ""},
             {"first": "Po-Ren", "middle": [], "last": "Hsueh", "suffix": "", "affiliation": {"laboratory": "", "institution": "National Taiwan University College of Medicine", "location": {"settlement": "Taipei", "country": "Taiwan"}}, "email": ""}
         ]
}
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 arya sianati