I am trying to learn how to read from a json file in Python and I am not sure how to interpret the error that I am getting I have posted my code below along with the error messages that I am getting. Any ideas? Thanks!
import json
filename = 'population.json'
with open(filename) as f:
pop_data = json.load(f)
for pop_dict in pop_data:
if pop_dict['Year'] == '2010':
country_name = pop_dict['Country Name']
population = pop_dict['Value']
print(country_name + ":" + population)
Error Msg----
C:\Anaconda\python.exe "C:/PyCharm/Data Visual/Pop.py"
Traceback (most recent call last):
File "C:/PyCharm/Data Visual/Pop.py", line 4, in <module>
pop_data = json.load(f)
File "C:\Anaconda\lib\json\__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\Anaconda\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Anaconda\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Anaconda\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Process finished with exit code 1