4

I'm currently working on a project which needs some server-client communication. We're planning to use Websockets and a Java server (Jetty) on the server side. So, messages sent must be interpreted with Java from the server and with JavaScript from the client.

Now we're thinking about a protocol and which structure the messages should have. We already have a reference implementation which uses XML messages. But since JSON is designed to be used with JavaScript we're also thinking about the possibility to use JSON-Strings.

Messages will contain data which consists of XML strings and some meta information which is needed to process this data (i.e. store it in a database, redirect is to other clients...). It would be important if the processing of the messages (parsing and creating) would be easy and fast on both server and client side since the application should feature real time speed.

Since we have not the time to test both of the technologies I would be happy about some suggestions based on personal experience or on technical aspects. Is one of the technics more usable than the other or are there any drawbacks in one of them?

Thanks in advance.

j0ker
  • 4,069
  • 4
  • 43
  • 65

4 Answers4

10

JSON is infinitely easier to work with, in my opinion. It is far easier to access something like data.foo.bar.name than trying to work your way to the corresponding node in XML.

XML is okay for data files, albeit still iffy, but for client-server communication I highly recommend JSON.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Also JSON is more lightweight in comparison to XML and thus better in terms of performance. – jagse Dec 11 '11 at 13:20
2

I agree with Kolink,

The reason, it is better to use JSON because the XML has a big Header, which means each transfer has a big overhead.

For iOS or Android, you have to use JSON as opposed to WLAN XML.

Lailo
  • 641
  • 1
  • 8
  • 24
2

You are opening a can of worms (again, not the first time).

have a look at this JSON vs XML. also a quick serach on stackoverflow will also be good.

this question might be duplicated across. Like this Stackoverflow XML vs JSON.

In the end answers stays the same. It depends on you. I though agree with many comments there that sometime, XML is overkill (and sometime not).

Community
  • 1
  • 1
manocha_ak
  • 904
  • 7
  • 19
1

I agree with Kolink, but if you already have an XML scheme in place, I'd use XML to save you some headaches on the Java-side. It really depends on who's doing the most work. Also, JSON is more compact, so you could save bandwidth using its format.

There seem to be some libraries for parsing JSON in Java, so it may not be too hard to switch formats. http://json.org/java/

Jeffrey Sweeney
  • 5,986
  • 5
  • 24
  • 32