I am trying to understand which data format is better on embedded device communicating with Server over REST API. XML or JSON?. Is JSON parsing faster than XML parsing in Java / C and C++? I understand for web client JSON is way to go since java script has inbuilt support for JSON but not sure about embedded device(Java/C/C++).
feedback
|
If the content has a lot of tags and not much content, JSON is better for the network because the size of the messages will be smaller. Now if the reverse is true, lots of content and not a lot of tags, JSON loses it's message size advantage somewhat, because regardless there is a large message coming across. I am not sure about the parsing. I would load up the same XML/JSON sample data that the application would be using and run them through the parsers you are planning on using and see which one performs better. If the parsers you are using load the XML/JSON into an object model of some sort, the performance should be about equal, but a quick test should prove if there is any real difference in parsing speed. | |||
feedback
|
XML is probably better if you need to do something with the message beyond simply deserializing it (e.g., if you need to pull some routing or processing information out of it with an XPath expression). XML can give you some additional validation tools (like schema validation), and may make more sense if messages need to be archived and potentially processed again later. But if all you need is a transport format, you may be better off sticking with JSON, especially if the bulk of your processing work is going to be done on the client. | |||
feedback
|
They are both text-based so the difference in performance between the two won't be as big as say the difference between XML/JSON and a good binary format like XDR. So if you want optimal performance then you should probably consider going binary. Having said that, one reason why XML might be faster is because it has been around for longer and there are some highly-optimized parsers and libraries that have been developed, especially if you have the schema for your vocabulary (e.g., XML Schema). Speaking of schemas, specification and validation of data is also something that you may want to consider; XML has much better support in this area. One example of such highly-optimized XML processing tool for embedded/mobile C++ is XSD/e. The website has some indicative performance numbers as well. | |||
feedback
|