Wednesday, September 12, 2012

Creating JSON object in JQuery/Javascript

Creating JSON object in JQuery/Javascript


    var jsonobj = {};

    jsonobj["employee"] = {};
    jsonobj["employee"]["employeename"] = "Balajiprasad";
    jsonobj["employee"]["companyname"] = "Microsoft";
    jsonobj["employee"]["CompanyAddress"] = {};
    jsonobj["employee"]["CompanyAddress"]["Address1"] = "IT park";
    jsonobj["employee"]["CompanyAddress"]["Address2"] = "SEZ Area";
    jsonobj["employee"]["CompanyAddress"]["City"] = "Bangalore";
    jsonobj["employee"]["CompanyAddress"]["Country"] = "India";
    jsonobj["personal"] = {};
    jsonobj["personal"]["personalname"] = "Balajiprasad";
    jsonobj["personal"]["Place"] = "Coimbatore";



OUTPUT

{
 "employee": {
  "employeename": "Balajiprasad",
  "companyname": "Microsoft",
  "CompanyAddress": {
   "Address1": "IT park",
   "Address2": "SEZ Area",
   "City": "Bangalore",
   "Country": "India"
  }
 },
 "personal": {
  "personalname": "Balajiprasad",
  "Place": "Coimbatore"
 }
}


No comments:

Post a Comment