Python: How to Solve raise JSONDecodeError(“Expecting value”, s, err.value) from None json.decoder…

When dealing with the local JSON file, because of the change of the JSON format, the code can not run and the error occurs. Here are the solutions:

[initial code]

with open(path,'r') as f:
    a = json.loads(f.read())
    print(a)
    print(type(a))

[prompt error]

Traceback (most recent call last):
  File "C:\Users\14062\Desktop\json02.py", line 25, in <module>
    c = json.loads(b)
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\14062\AppData\Local\Programs\Python\Python37-32\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)

[solution]

with open(path,encoding='utf-8-sig', errors='ignore') as f:
     data = json.load(f, strict=False)
     print(data)

Similar Posts: