Ali Ali - 5 months ago 32
JSON Question

Json.load() , Json.loads() is not working in python 2.7

I want to use

json
library and run the code

import json

data = ''' {
"name" : "Chuck",
"phone": {
"type" : "intl",
"number" : "+1 734 355 4544"
}
"email" :{
"hide" : "yes"
}
} '''

info = json.load(data)
print 'Name : ', info["name"]
print 'Hide:' , info["email"]["hide"]


It is showing the error "return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'
"

Any solution for it?
Edited version

Answer

You've named your program json.py which conflicts with the built-in module json.

Rename your program to my_program.py and delete json.py and json.pyc from your directory.

Comments