XML, JSON, or what?

Alan Kennedy alanmk at hotmail.com
Thu Jun 8 11:49:06 CEST 2006


[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.
>
> At first, I used XML as a message format. Then I read the article that
> recommended not using XML for Python-to-Python, so I changed it to a
> pickled collection of Python objects. It works just as well.

If you were just communicating python to python, I'd recommend Pyro,
since it has all the socket management, etc, already taken care of.

http://pyro.sourceforge.net

> At present the client uses wxPython. One of my medium-term goals is to
> write a web-based client. I don't think it will be easy to reproduce
> all the functionality that I have at present, but I hope to get close.
> I have not done any serious research yet, but I am pretty sure I will
> use javascript on the client, to make it as universal as possible.

If you're going to mix javascript client and python server, you
definitely need something cross platform, like XML or JSON.

> Ideally, the server should be able to handle a wxPython client or a web
> client, without even knowing which one it is talking to. Obviously I
> cannot use Pickle for this. So my question is, what is the ideal format
> to use? I could go back to XML, or I could switch to JSON - I have read
> a bit about it and it does not seem complicated.

JSON is indeed (mostly) as simple as it looks: it fits your need very
well. And you should be up and running with it very quickly.

> My messages are not
> very large (maximum about 2k so far for a complex screen layout) so I
> don't think performance will be an issue.

And parsing JSON will almost certainly be faster than parsing XML. You
should easily be able to parse hundreds or maybe thousands of 2K JSON
messages a second. And JSON generation and parsing is at least as well
supported and robust as XML, in most languages.

> I would rather make a decision now, otherwise I will have a lot of
> changes to make later on. Does anyone have any recommendations?

I'd go with JSON, for simplicity and portability.  If you have any
specific questions about it, ask.

regards,

--
alan kennedy
------------------------------------------------------
email alan:              http://xhaus.com/contact/alan




More information about the Python-list mailing list