views:

49

answers:

2

I use the json module and the dumps method to obtain a string which represents a list of json objects :

import json
jsonstring = json.dumps(data)

I would like to iterate over this string to obtain each JSON object as a string.

Any suggestions?

Thanks in advance.

P.S. I have tried the following:

for jsonobject in jsonstring:
    print jsonobject

But what happens is that each single letter is printed separately rather than the jsonobject as a whole.

+1  A: 

You should iterate over your data before you turn it into a string, then turn each element of the data into JSON:

for d in data:
    jsonstring = json.dumps(d)
Ned Batchelder
thanks ned! that does exactly what i need and didn't realize it. sorry about the noobiness...
Al Jepo
A: 
for jsonobject in json.loads(jasonstring):
    print jsonobject
gnibbler
thanks john. this does it... and jsonobject is a unicoded string.
Al Jepo