I am trying to send a simple dictionary to a json file from python, but I keep getting the message "TypeError: 1425 is not JSON serializable".
import json alerts = {'upper':[1425],'lower':[576],'level':[2],'datetime':['2012-08-08 15:30']} afile = open('test.json','w') afile.write(json.dumps(alerts,encoding='UTF-8')) afile.close()
If I add the default argument, it writes, but the integer values โโare written to the json file as strings, which is undesirable.
afile.write(json.dumps(alerts,encoding='UTF-8',default=str))
json python encoding typeerror
user1329894 Aug 13 '12 at 21:10 2012-08-13 21:10
source share