Zope Python Script JSON Serialize a result set object

The Python JSON-RPC library doesn't allow direct serialization of a result set object.

But, you can iterate over the rows and fields of the result set dynamically to produce an object that can be serialized to JSON.
from jsonrpc import json
users = context.sql_search_users(keyword = context.REQUEST.get('keyword'))
fields = users.data_dictionary().keys()
userArray = []
for user in users:
	userDict = {}
	for field in fields:
		userDict[field] = user[field]
return json.dumps(userArray)
Posted by
Snippet Viewed 3459 times.

Share your Zope Python Script code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent zope python snippets

Most Viewed