Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling messages with Java and JavaScript: JSON or XML?

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.

like image 683
j0ker Avatar asked Dec 07 '22 17:12

j0ker


2 Answers

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.

like image 92
Niet the Dark Absol Avatar answered Dec 09 '22 06:12

Niet the Dark Absol


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

like image 37
manocha_ak Avatar answered Dec 09 '22 05:12

manocha_ak