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++).
2 Answers
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.
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.
-
Currently there is no way to do performance testing on the device itself hence I posted question here. Thx for your answer.– FarmAug 3, 2011 at 23:41
-
1Since "there is no way to do performance testing on the device itself", how would anyone else know how it performs on your device? If you can't test it on the device itself, you can make a test on your computer instead. Feb 12, 2015 at 12:18