XML, JSON, or what?

Frank Millman frank at chagford.com
Fri Jun 16 10:06:36 EDT 2006


Alan Kennedy wrote:
> [Frank Millman]
> > I am writing a multi-user accounting/business application, which uses
> > sockets to communicate between server and client. The server contains
> > all the business logic. It has no direct knowledge of the client. I
> > have devised a simple message format to exchange information between
> > the two.
> >
>
> If you're going to mix javascript client and python server, you
> definitely need something cross platform, like XML or JSON.
>
[...]
>
> I'd go with JSON, for simplicity and portability.  If you have any
> specific questions about it, ask.
>

Thanks for the offer. I have just tried it out, and instantly bumped my
head. I think I know the problem, and I don't think there is a simple
answer, but I will ask here first before starting to figure out a way
around it.

My client-server is Python-to-Python. At present, I am using cPickle to
transfer objects between the two. Among other things, I sometimes
transfer a tuple. Using JSON it appears on the other side as a list. As
I sometimes use the tuple as a dictionary key, this fails, as you
obviously cannot use a list as a key.

I am using 'simplejson'. I see there is also something called json-py,
but I have not tried it yet, as I am assuming (maybe wrongly) that it
will have the same problem. My hunch is that javascript/JSON does not
have the concept of a tuple, and therefore the problem is inherent.

Can someone confirm this, or is there an easy workaround?

Thanks

Frank




More information about the Python-list mailing list