Python ValueError: No JSON object could be decoded
For me it was an encoding problem, you can try using Notepad++ to edit your .json file and change the Encoding to UTF-8 without BOM. Another thing you could check is if your json script is valid
It's possible the .read()
method is moving the cursor to the end of the file. Try:
for filename in filenames:
with open(os.path.join(dirname,filename)) as fd:
json_data = json.load(fd)
and see where that gets you.
This, of course, assumes you have valid JSON, as your example demonstrates. (Look out for trailing commas)
I resolved this error by Converting the json file to UTF-8 with no BOM. Below is a python snippet and url for conversion
myFile=open(cases2.json, 'r')
myObject=myFile.read()
u = myObject.decode('utf-8-sig')
myObject = u.encode('utf-8')
myFile.encoding
myFile.close()
myData=json.loads(myObject,'utf-8')