Pages

Saturday, April 7, 2012

[Python] Load json into dict and vice versa

##Load json to dict
f = open('myFile.json','r').read()
#objs is stored in dict form data
obj = json.loads(f)


##Save dict to a json file
testDic = {'a':123,'b':2}
#print type(testDic)
f = open('test2.json', 'w')
json.dump(testDic, f, indent=4)

No comments:

Post a Comment