Need help?

I'm available for remote short term contracting or consultancy work. Please check out my LinkedIn profile for more details on my experience.

Please feel free to use the form below to contact me.




JSON or XML in Android

The big question here is which technology to use, JSON vs XML. They both do a very good job, so what are the benefits of using one or the other? Well, I'm going to list the pros and cons of each, coming from a mobile point of view.

If's you're not too familiar with JSON and XML, I'll do a quick brief. They are basically used for defining and storing data (using meta data). This data can then be passed around - so when it travels from point A to B, the receiving end will know what each piece of information means (just to maintain a certain level of standardization).

Here are some examples of what it would look like in XML and JSON (in that order):


<?xml version="1.0"?>
<note>
    <to>Santa</to>
    <from>Joe</from>
    <heading>Reminder</heading>
    <body>Don't forget my presents!</body>
</note>


{"note": {
  "to": "Santa",
  "from": "Joe",
  "heading": "Reminder",
  "body": "Don't forget my presents!",
}}

Now those are very simple examples, but it gives you the general idea. You should also check out these 2 sites for additional information, or just search it in Google: XML and JSON.

Lets disect those a bit - what's the biggest things you notice? Probably the fact that the XML is a lot easier to read, and that JSON has a smaller footprint.

Taking into consideration those 2 examples, here's a list of pros and cons for each, from a mobile point of view.

XML Pros

  • Easier to read
  • Used a lot more than JSON
  • One of the main industry standards

XML Cons

  • Takes up more space
  • Increased bandwidth because of the size

JSON Pros

  • Doesn't take up a lot of space
  • Uses less bandwidth because of it's size (footprint)
  • Rising in the ranks as one of the main industry standards

JSON Cons

  • Harder to read

I think the main points here are the size differences - since we're dealing with mobile devices, which have speed constraints (which could also cost people a lot of money for bandwidth), size is very important.

To conclude, I believe that the best option for mobile devices (Android in this case) is to use JSON. The small footprint will speed up transactions between your app and the web services you're trying to send/receive data to/from. Or if you're using it for something else, it'll still be quicker.

Any comments are welcome, as I'm sure everyone has their own opinion.


jon | April 27, 2011 | Comments (2)

Comments

XML Pros:
XmlPullParser - doesn't require to store whole xml in memory, is there any similar efficient json parser for Android? Moreover when you enable Gzip there wouldn't be much of difference in sizes. This is still better trade-off when using XML over JSON I guess.
Comment by jasom - August 17, 2012 @ 5:22 am
In awe of that ansewr! Really cool!
Comment by Taran - May 07, 2011 @ 7:21 am

Name (required)
Email (will not be published) (required)
Website

captcha