Saturday, February 21, 2009

Use JSON to transfer information in a Mobile Application or encode information in a 2D Barcodes

I was introduced to JSON being used as a very lightweight data interchange format while working on building Web 2.0 applications at work. I realized the immense advantages of JSON while working on a mobile application project dealing with two dimensional project at San Jose State.


So first what is JSON, there are good links out there already:

1. JSON in Java

In short, an XML Doc Horror BookSmith can be shown in JSON as:


{
"name": "Horror Book"
"author":"Smith"
}

Where we used JSON and Why?

First, the project required us to exchange information between a client on a mobile phone emulator and a web server. XML is the first obvious choice or just a series of comma separated values, etc. We chose JSON since there were good libraries to place information in a structured manner in JSON and to read it on the other side. No need of using some XML parser and stuff. Space saved for closing tags, etc.

Second, the application was designed such that receipt of purchase would be stored in a 2D Barcode and sent to the mobile phone emulator. As per the project, in the real world, the user would take the barcode to the retailer as a proof of receipt. There were other security related use of 2D Barcodes as well. Again, 2D barcodes cannot save a lot of information. JSON and its libraries would provide us a very compact way to store info in the barcode and read it back.

Today, I also noticed an article discussing other uses of JSON in mobile apps here.

See here for using JSON in J2ME