Skip to content Skip to sidebar Skip to footer

Json.decoder.jsondecodeerror: Expecting Value: Line 1 Column 1 (char 0)

I am trying to import a file which was saved using json.dumps and contains tweet coordinates: { 'type': 'Point', 'coordinates': [ -4.62352292, 55.44787441

Solution 1:

json.loads() takes a JSON encoded string, not a filename. You want to use json.load() (no s) instead and pass in an open file object:

withopen('/Users/JoshuaHawley/clean1.txt') as jsonfile:
    data = json.load(jsonfile)

The open() command produces a file object that json.load() can then read from, to produce the decoded Python object for you. The with statement ensures that the file is closed again when done.

The alternative is to read the data yourself and then pass it into json.loads().

Solution 2:

I had similar error: "Expecting value: line 1 column 1 (char 0)"

It helped for me to add "myfile.seek(0)", move the pointer to the 0 character

withopen(storage_path, 'r') as myfile:
iflen(myfile.readlines()) != 0:
    myfile.seek(0)
    Bank_0 = json.load(myfile)

Solution 3:

Please use this function

defread_json_file(filename):
    withopen(filename, 'r') as f:
        cache = f.read()
        data = eval(cache)
    return data

another function

def read_json_file(filename):
    data = []
    with open(filename, 'r') as f:
        data = [json.loads(_.replace('}]}"},', '}]}"}')) for _ in f.readlines()]
    returndata

Post a Comment for "Json.decoder.jsondecodeerror: Expecting Value: Line 1 Column 1 (char 0)"