Resolve "AttributeError str object has no attribute read" with json.load

by
Jeremy Canfield |
Updated: May 28 2023
Let's say something like this is being returned.
AttributeError: 'str' object has no attribute 'read'
I have run into this error before when I have mistakenly used the variable that contains the full path to my JSON file instead of the variable associated with open the JSON file.
#!/usr/bin/python
import json
json_file = "/path/to/example.json"
file = open("/path/to/example.json")
parsed_json = json.load(json_file) <- this should be "file" not "json_file"
file.close()
Did you find this article helpful?
If so, consider buying me a coffee over at