Load / reset JSON in Python

From the docs: http://docs.python.org/library/json.html

>>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') [u'foo', {u'bar': [u'baz', None, 1.0, 2]}] 

I changed it like this:

 >>> the_dump=json.dumps("['foo', {'bar':['baz', null, 1.0, 2]}]") >>> the_load = json.loads(the_dump) u"['foo', {'bar':['baz', null, 1.0, 2]}]" 

Now this is a string. I want to do this: the_load[1]['bar'] .

Is it possible to do so? Where am I mistaken?

Why does this work?

 >>> a= "[1,2,3]" >>> json.loads(a)[0] 1 
+7
source share
1 answer
 >>> the_dump=json.dumps("['foo', {'bar':['baz', null, 1.0, 2]}]") 

You ask his json to encode the string, so it is not surprising that when decoding you return the string. Try instead:

 >>> the_dump=json.dumps(['foo', {'bar':['baz', None, 1.0, 2]}]) 
+12
source

All Articles