On Dec 20, 5:04 pm, "Rick Morrison" <[EMAIL PROTECTED]> wrote:
> You're not going to be able to serialize Python class instances in JSON:
> json strings are simple object literals limited to basic Javascript types.
> Pickle does some pretty heavy lifting to serialize and reconstitute class
> instances.

I've already figured this out -- you can use class "hinting" as
outlined in this page:

http://json-rpc.org/wiki/specification

So a datetime using this format and converted to JSON might look like:

"modification_time": {"__jsonclass__": ["datetime.datetime", [2007,
12, 19, 23, 3, 2, 2]]}

My deserialization routine loads the datetime module, then gets the
datetime attribute (which in this case is a type, but could be a
function too), and calls that with the arguments in the list.  This
sort of thing works for generic classes too using the pickle
__reduce__ hooks.  The JSON part I'm actually handling through cjson
or simplejson -- my serialization/deserialization is working all on
python objects.

> Easiest way to store JSON in the database is to limit the type of data you
> store in JSON strings to straightforward objects that only use primitive JS
> types, and then serialize back and forth to Python dictionaries. That's what
> libraries like SimpleJSON or cJSON do. Using Sqlalchemy, you can then store
> those JSON strings in database VARCHARS, TEXT and so on fields.

I don't really want to store JSON in the DB, but just use it as a
serialization format for sqlalchemy objects.  We want our frontend to
render data from the same type of object with a couple different
possible backend sources.  One being the database through the
sqlalchemy ORM and another being some sort of JSON/XML interface that
we can backend from whatever...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to