Answer the question
In order to leave comments, you need to log in
json.decoder.JSONDecodeError error when reading json file, how to fix?
Hello, when I try to read a json file, I get an error:
Traceback (most recent call last):
File "C:\Users\GroMan\PycharmProjects\PaperRockScissors\app.py", line 125, in
main()
File "C:\ Users\GroMan\PycharmProjects\PaperRockScissors\app.py", line 64, in main
dire = json.load(jsonconfig)
File "C:\Users\GrroMan\AppData\Local\Programs\Python\Python39\lib\json\__init__ .py", line 293, in load
return loads(fp.read(),
File "C:\Users\Mary\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\GroMan\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337,in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Mary\AppData\Local\Programs\Python\Python39\lib\json\decoder.py" , line 355, 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
Here is the code to read the file:
jsonconfig = open('media/config.json', 'r', encoding='utf-8')
if json.load(jsonconfig)['DEBUG']:
dire = json.load(jsonconfig)
dire = dire['directory']
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question