views:

173

answers:

2

It's something like this, but this example seems a little complicated.

import simplejson as json json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])

My dictionary is:

myfruits = {'fruit':4, 'color':11}

How can I turn this into a JSON, and then use render_to_response to shoot it to a template? I'm using Django.

+1  A: 

use json.dumps() (see doc here).

import simplejson
simplejson.dumps({'fruit':4, 'color':11})
jldupont
+3  A: 

I think this is the easiest way to do it

import simplejson as json 
myfruits = {'fruit':4, 'color':11}
json.dumps(myfruits)
jbochi