Handling messages using Java and JavaScript: JSON or XML?

I am currently working on a project that requires interaction with the server and client. We plan to use Websockets and a server server (Jetty) Java. Therefore, messages sent must be interpreted from Java from the server and from JavaScript from the client.

Now we are thinking about the protocol and structure that messages should have. We already have a reference implementation that uses XML messages. But since JSON is intended for use with JavaScript, we are also thinking about the possibility of using JSON-Strings.

Messages will contain data that consists of XML strings and some meta-information necessary for processing this data (i.e. store it in a database, redirect it to other clients ...). It would be important for message processing (parsing and creation) to be simple and fast on the server and client side, since the application must use real-time speed.

Since we do not have time to test both technologies, I would be glad to have some suggestions based on personal experience or on technical aspects. Is one of the techniques more useful than the other, or are there any flaws in one of them?

Thanks in advance.

+4
source share
4 answers

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

XML is well suited for data files, although iffy anyway, but for client-server interaction I highly recommend JSON.

+10
source

I agree with Kolink,

For this reason, it is better to use JSON because XML has a large header, which means that each transmission has a large overhead.

For iOS or Android, you should use JSON, not WLAN XML.

+2
source

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

look at JSON vs XML . A quick serach on stackoverflow will also be very helpful.

this question may be duplicated. Like fooobar.com/questions/2536 / ....

In the end, the answers remain unchanged. It depends on you. I agree with many comments there that once upon a time, XML is crowded (and sometimes not).

+2
source

I agree with Kolink, but if you already have an XML schema, I would use XML to save you some headaches on the Java side. It really depends on who works the most. In addition, JSON is more compact, so you can save bandwidth in the format.

It seems that there are several libraries for parsing JSON in Java, so it may not be too hard to switch formats. http://json.org/java/

+1
source

Source: https://habr.com/ru/post/1385744/


All Articles