how to read json object in python

You should pass the file contents (i.e. a string) to json.loads(), not the file object itself. Try this:

with open(file_path) as f:
    data = json.loads(f.read())
    print(data[0]['text'])

There’s also the json.load() function which accepts a file object and does the f.read() part for you under the hood.

Leave a Comment