I just started learning JSON, and I want to read a JSON file from my PC.
I tried this with json.loads(), I am getting this error: json.decoder.JSONDecodeError: Expecting ',' delimiter: line 9 column 20 (char 135).
So I tried to load the data from JSON file from my PC , with open(), but I found out that it doesn't return a String type output, and it gives the error: TypeError: the JSON object must be str, bytes or bytearray, not TextIOWrapper.
Then I tried using read() and also gives the error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I've tried these:
1)
with open('FILE.json') as f:
data = json.loads(f.read())
2)
with open('FILE.json') as f:
data = json.loads(f)
3)
with open('FILE.json', 'r', encoding='utf-8') as f:
data = json.loads(f.read())
Expecting value: line 1 column 1 (char 0)means that you read from empty file. It can't decode empty string. Better check what you have in this file. Or maybe you read from different file than you expect.f.seek(0)to move back to the start.line 9 column 20 (char 135). This is indicating there is a formatting error in your JSON file you need to fix, your first example will actually correctly read JSON provided the format is correct.