understanding JSON

JSON stands for JavaScript Object Notation.It's lightweight data interchange format.It is a text-based, human-readable format for representing object and other data structures and is mainly used to transmit such structured data over a network connection (in a process called serialization).It is based on subset of javascript.

JSON is a self-contained unambiguous data representation format, and since it carries no executable or algorithmic meaning it is inherently secure by itself. However security issues may arise if a program incorrectly processes JSON-formatted data as if it were something else. Since the JSON syntax is by design a subset of the Javascript syntax, most security concerns involve having a Javascript interpreter directly process JSON text as if it were Javascript source code.

The following example shows the JSON representation of an object that describes a employe. The object has string fields for first name and last name,company name,designation contains an object representing the person's address, and contains a list of phone numbers (an array).


{
   "firstName": "Uttam",
   "lastName": "Kumar", 
   “companyName” :”magnet”, 
   “designation”:”Sr. web Developer”,
   "address": {      
     "streetAddress": "Patankar street", 
            "city": "Nsp(w)",
             "state": "MH",
            "postalCode":401203     
               },
 "phoneNumbers": [ "212 732-1234","646 123-4567"]
 }

Suppose the above text is contained in the JavaScript string variable employee. Since JSON is a subset of JavaScript's object literal notation, one can then recreate the object describing Uttam Kumar with a simple eval() function which is as follows

 var emp = eval("(" + employee + ")");  Now we can access firstName,city,phone number by the following. 
emp.firstName //property of object
emp.address.city //sub property of object 
emp.phoneNumbers[0]//array
 similerly we can access all the values.