473,414 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

XML, JSON, or what?

Hi all

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.

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.

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. 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.

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

Thanks

Frank Millman

Jun 8 '06 #1
10 2968
On 2006-06-08, Frank Millman <fr***@chagford.com> wrote:
I would rather make a decision now, otherwise I will have a lot of
changes to make later on. Does anyone have any recommendations?


Did you consider XMPP?
With XMPP you create XML streams between your server and the client.
XMPP is an open standard (by the IETF).

Jabber (jabber.org) is based on the XMPP standard. They develop protocols on
XMPP for all kinds of data exchange. Currently, it is mainly used for chatting,
but we use it in-house as publish/subscribe to control some machines too.
They do a lot of thinking about scalabilty, privacy, authentication, and all
that other stuff you need to do when you put some service on the internet.

They also have protocols for using a GUI interactively (much like the wizards
of Win* do, you get one page of things to decide, you press 'next', you get the
next page, etc).

Albert
Jun 8 '06 #2
Ant
> to use? I could go back to XML, or I could switch to JSON - I have read

I'd favour JSON if the data structures are simple personally. XML is
comparatively speaking a pain to deal with, where with JSON you can
simply eval() the data and you have a Python dictionary at your
disposal.

I recently used JSON as a way of passing data from a Java backend to a
web page for Javascript to deal with, with the added side effect that
my Python testing scripts could also easily read the same data.

Jun 8 '06 #3
[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

Jun 8 '06 #4
Ant wrote:
to use? I could go back to XML, or I could switch to JSON - I have read

I'd favour JSON if the data structures are simple personally. XML is
comparatively speaking a pain to deal with, where with JSON you can
simply eval() the data and you have a Python dictionary at your
disposal.

Modulo any security problems that alert and malicious users are able to
inject into your application. Simply using eval() uncritically on
whatever comes down the pipe is a train wreck waiting to happen.
I recently used JSON as a way of passing data from a Java backend to a
web page for Javascript to deal with, with the added side effect that
my Python testing scripts could also easily read the same data.


Oh, well as ling as we're talking about the *web* that's all right, then :-)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 8 '06 #5
[Ant]
I'd favour JSON if the data structures are simple personally. XML is
comparatively speaking a pain to deal with, where with JSON you can
simply eval() the data and you have a Python dictionary at your
disposal.

[Steve] Modulo any security problems that alert and malicious users are able to
inject into your application. Simply using eval() uncritically on
whatever comes down the pipe is a train wreck waiting to happen.


Yes, evaling JSON, or any other text coming from the web, is definitely
a bad idea.

But there's no need for eval: there are safe JSON codecs for python,

http://cheeseshop.python.org/pypi?%3...scription=json

And one for javascript,

http://www.json.org/js.html
http://www.json.org/json.js

And most other languages you're likely to come across.

http://www.json.org/

regards,

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

Jun 8 '06 #6
Ant
Yes, evaling JSON, or any other text coming from the web, is definitely
a bad idea.

But there's no need for eval: there are safe JSON codecs for python,


Fair enough. And I should imagine that the codecs are still much faster
and easier to use than XML for the same purpose.

For my purposes, the JSON is pushed out to the web from our Java
web-app, and eval'd in the test scripts which screen scrape the JSON
structure from the web page - no danger in this case for me. But yes -
I wouldn't be eval'ing random 'JSON' code from the web :-)

Jun 8 '06 #7

Frank Millman wrote:
Hi all

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.
[...]
I would rather make a decision now, otherwise I will have a lot of
changes to make later on. Does anyone have any recommendations?

Thanks

Frank Millman


Thanks for the replies, guys.

Albert, thank you for the pointer to XMPP. I had not heard of it, but
it looks very interesting. I will have to investigate further before
deciding whether it is right for my application. If not, JSON it is.

Frank

Jun 9 '06 #8

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

Jun 16 '06 #9
> 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. [...] Can someone confirm this, or is there an easy workaround?


You can always convert a list to a tuple using the tuple () builtin
right before you use it as a key. But you have to be sure that it is a
list. tuple ("abc") => ('a', 'b', 'c') is probably not what you intend
to do.

Daniel
Jun 16 '06 #10

Daniel Dittmar wrote:
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.

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


You can always convert a list to a tuple using the tuple () builtin
right before you use it as a key. But you have to be sure that it is a
list. tuple ("abc") => ('a', 'b', 'c') is probably not what you intend
to do.

Daniel


Thanks,Daniel. After sleeping on it, I had also come to the conclusion
that this is the easiest solution -
if isinstance(key,list):
key = tuple(key)

A bit of a kludge, but I can live with it. I will keep checking to see
if any other anomalies crop up.

Frank

Jun 17 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Jempty | last post by:
In my journal anyway: "JSON: Javascript Unusable by the Client" http://slashdot.org/~scriptify/journal/103074
16
by: G Matthew J | last post by:
http://htmatters.net/htm/1/2005/07/evaling-JSON.cfm This is more or less in response to Mr Crockford's admonition a few months ago, "fork if you must". Ironically, although in that usenet post...
20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
3
by: Adam | last post by:
I'm trying to retrieve some values from a json object, but instead it's giving me the property name. For example: var json = { "glossary": { "title": "example glossary" } }; console.log(json);...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
6
by: dd | last post by:
I'm writing something in JS using the latest OO and JSON and I'm looking for a bit of guidance. I'm going to have this large object which has many top-level properties and some top-level...
23
by: dhtmlkitchen | last post by:
JSON We all know what it is. In ECMAScript 4, there's a JSON proposal: Object.prototype.toJSONString String.prototype.parseJSON The current proposal, String.prototype.parseJSON, returns...
9
by: Jon Paal [MSMD] | last post by:
using json like ( {"Records": , "RecordCount":"1" } ) and jquery like: $.ajax({ .... success: function(json, status) {
6
by: Lasse Reichstein Nielsen | last post by:
Max <adsl@tiscali.itwrites: Not really. It shows that a particularly naïve implementation of a conversion from XML to JSON doesn't work well. What if the conversion of <e> some
0
by: crocodilu2008 | last post by:
JSON vs. XML JSON and XML are basically used for the same purpose—to represent and interchange data. I'll try to show you why you might want to use JSON rather than XML in an AJAX context by showing...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.