I am learning how to use json module in python from here: http://www.fantasyfutopia.com/python-for-fantasy-football-apis-and-json-data/
When I am running the exact copy paste code (only changing the url), I am getting this error:
import pandas as pd
import json
import requests
from pandas.io.json import json_normalize
# Define a function to get info from the FPL API and save to the specified file_path
# It might be a good idea to navigate to the link in a browser to get an idea of what the data looks like
def get_json(file_path):
response = requests.get("https://understat.com/league/EPL")
jsonResponse = response.json()
with open(file_path, 'w') as outfile:
json.dump(jsonResponse, outfile)
# Run the function and choose where to save the json file
get_json('C:\\Python Advanced/python-for-fantasy-football-master\\python-for-fantasy-football-master\\4 - APIs and JSON Data\\EPL_team.json')
# Open the json file and print a list of the keys
with open('C:\\Python Advanced/python-for-fantasy-football-master\\python-for-fantasy-football-master\\4 - APIs and JSON Data\\EPL_team.json') as json_data:
data = json.loads(json_data)
print(list(data.keys()))
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-29-6322b86c0ee6> in <module>
15
16 # Run the function and choose where to save the json file
---> 17 get_json('C:\\Python Advanced/python-for-fantasy-football-master\\python-for-fantasy-football-master\\4 - APIs and JSON Data\\EPL_team.json')
18
19 # Open the json file and print a list of the keys
<ipython-input-29-6322b86c0ee6> in get_json(file_path)
9 def get_json(file_path):
10 response = requests.get("https://understat.com/league/EPL")
---> 11 jsonResponse = response.json()
12
13 with open(file_path, 'w') as outfile:
C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in json(self, **kwargs)
896 # used.
897 pass
--> 898 return complexjson.loads(self.text, **kwargs)
899
900 @property
C:\ProgramData\Anaconda3\lib\json\__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
355 parse_int is None and parse_float is None and
356 parse_constant is None and object_pairs_hook is None and not kw):
--> 357 return _default_decoder.decode(s)
358 if cls is None:
359 cls = JSONDecoder
C:\ProgramData\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
C:\ProgramData\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I am still a newbie with json. My aim is to get TEAM data from the url. Kindly help.