[Baypiggies] newbie question - json as pickler

Keith Dart keith at dartworks.biz
Mon Feb 22 09:22:03 CET 2010


=== On Mon, 02/22, K. Richard Pixley wrote: ===
> Problem #1: most json encoders, (including the standard library json 
> module), don't encode/decode arbitrary objects.  They seem to be
> aiming for cross language exchange rather than persistence or
> serialization of python-to-python transfers.  I have found a couple
> on the cheese shop that do use a standard encoding, so this isn't
> necessarily a blocker.

Right. If you want Python-to-Python transfers why not use pickle?
The default format IS text, and is actually readable once you learn a
little of the format. 


> Problem #2: the object encoding serializers that I've found are
> strictly string->object and object->string.  This would seem to make
> a number of things awkward.  Spitting out a sequence of objects as a
> sequence of strings is easy.  However, it's looking to me as though
> reading that sequence of strings will require parsing the incoming
> stream in order to divide them up into chunks suitable for handing
> off to the deserializer.  This seems like it makes the serializers
> essentially useless.

I don't think you should be trying to slice the serialized byte stream
since it is supposed to be opaque data. 

You can pickle arbitrary objects. The main limitation there is that
class instances don't pickle the whole class, but refer to the class by
name. Therefore when you unpickle that instance the class object must be
available, and on the same "package path". The exact class type is not
even checked, so you can unpickle to a different class implementation
than you pickled with. I've exploited this myself when transferring
objects between Linux and Windows. ;-)

However, if all you want to transfer and/or store are basic data types
then JSON serialization could work. It is possible to extend it with a
custom hack to transfer more complex types, but it won't be portable.



-- Keith Dart

-- 

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Keith Dart <keith at dartworks.biz>
   public key: ID: 19017044
   <http://www.dartworks.biz/>
   =====================================================================


More information about the Baypiggies mailing list