'dict' object has no attribute 'read'
Since you want to convert it into json
format, you should use json.dumps()
instead of json.load()
. This would work:
>>> import json>>> array = json.dumps({"name":"Galen","learning objective":"load json files for data analysis"})>>> array'{"learning objective": "load json files for data analysis", "name": "Galen"}'
Output:
>>> a = json.loads(array)>>> a["name"]u'Galen'
if you want to load json from a string you need to add quotes around your string and there is a different method to read from file or variable. For variable it ends with "s" other doesn't
import jsonmy_json = '{"my_json" : "value"}'res = json.loads(my_json)print res
I think you are after this:
import jsonarray = json.dumps({"name":"Galen","learning objective":"load json files for data analysis"})print(array)
Gives:
{"learning objective": "load json files for data analysis", "name": "Galen"}