Python dict to JSON via json.loads: Python dict to JSON via json.loads: python python

Python dict to JSON via json.loads:


You are trying to use the wrong method. json.loads is for loading JSON to Python. If you want to convert Python to JSON, you need json.dumps.

result = json.dumps(response[1])


That dict is in Python dict literal format, not JSON. You can do:

import astresult = ast.literal_eval(response[1])

to read in the response in that format. Are you sure that Django hasn't already JSON-decoded the response?


i have use json on django , i use this :

import simplejson as json#to encodefinal= {'first':first_data,'second':second_data}json.dumps(final)#to decode this is the example from python's api json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]')