[storm] How to JSON encode a item from a ResultSet
Mario Zito
mazito at analyte.com
Thu May 27 21:14:08 BST 2010
Hi, again:
I would like to iterate over all items of a returned ResultSet encoding each
one using JSON. Example code follows:
class Topic(object):
__storm_table__= "Trancos.topic"
id = Int(primary=True)
account_id= Int()
title= Unicode()
properties= Unicode()
notes= Unicode()
# and other attrs not important here ...
def do_query():
''' Query'''
engine= create_database("postgres://postgres:mypassword@localhost
/trancos")
store= Store(engine)
# execute the query and iterate over the ResultSet
rs= store.find(Topic)
for t in rs:
print t.id, json.dumps(t)
But I get the error:
File "/usr/lib/python2.6/json/encoder.py", line 344, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <__main__.Topic object at 0x26f3090> is not JSON serializable
Any ideas ? Is there a way to serialize a Storm object (or a full ResultSet)
to JSON ?
Sorry if this a strict Python language item !
Thanks.
Mario
--
Mario A. Zito
ANALYTE SRL
www.analyte.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20100527/660fb8ae/attachment.htm
More information about the storm
mailing list