title: MVC 4 Linq format json response
body: <p>I am able to get the following json output from my controller but I need to remove the "key" &amp; "value" from myDates &amp; myStaff, and group the appointment times by date - eg: date0, date1, date2..</p>
  
  <pre><code>{
  "myDates": [{
      "Key": "date0",
      "Value": "23/02/2013"
  }, {
      "Key": "date1",
      "Value": "24/02/2013"
  }, {
      "Key": "date2",
      "Value": "25/02/2013"
  }, {
      "Key": "date3",
      "Value": "26/02/2013"
  }, {
      "Key": "date4",
      "Value": "27/02/2013"
  }, {
      "Key": "date5",
      "Value": "28/02/2013"
  }, {
      "Key": "date6",
      "Value": "1/03/2013"
  }, {
      "Key": "dname0",
      "Value": "Saturday"
  }, {
      "Key": "dname1",
      "Value": "Sunday"
  }, {
      "Key": "dname2",
      "Value": "Monday"
  }, {
      "Key": "dname3",
      "Value": "Tuesday"
  }, {
      "Key": "dname4",
      "Value": "Wednesday"
  }, {
      "Key": "dname5",
      "Value": "Thursday"
  }, {
      "Key": "dname6",
      "Value": "Friday"
  }, {
      "Key": "ndate",
      "Value": "2013-03-02"
  }, {
      "Key": "pdate",
      "Value": "2013-02-16"
  }],
  "myStaff": [{
      "Key": "staff0",
      "Value": [
          [{
              "SlotID": 42501,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "23/02/2013",
              "SlotDay": "Saturday",
              "SlotTime": "10:00"
          }, {
              "SlotID": 42502,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "23/02/2013",
              "SlotDay": "Saturday",
              "SlotTime": "10:30"
          }],
          [{
              "SlotID": 47001,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "24/02/2013",
              "SlotDay": "Sunday",
              "SlotTime": "10:00"
          }, {
              "SlotID": 47002,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "24/02/2013",
              "SlotDay": "Sunday",
              "SlotTime": "10:30"
          }]
      ]
  }]
  }
  </code></pre>
  
  <p>basically, I need to get the json formatted like below:</p>
  
  <pre><code>{
  "myDates": [{
      "date0": "23/02/2013",
      "date1": "24/02/2013",
      "date2": "25/02/2013",
      "date3": "26/02/2013",
      "date4": "27/02/2013",
      "date5": "28/02/2013",
      "date6": "1/03/2013",
      "dname0": "Saturday",
      "dname1": "Sunday",
      "dname2": "Monday",
      "dname3": "Tuesday",
      "dname4": "Wednesday",
      "dname5": "Thursday",
      "dname6": "Friday",
      "ndate": "2013-03-02",
      "pdate": "2013-02-16",
  }],
  "myStaff": [{
      "staff0": {[ 
        "date0": {[
          [{
              "SlotID": 42501,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "23/02/2013",
              "SlotDay": "Saturday",
              "SlotTime": "10:00"
          }, {
              "SlotID": 42502,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "23/02/2013",
              "SlotDay": "Saturday",
              "SlotTime": "10:30"
          }],
        "date1": {[
              "SlotID": 47001,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "24/02/2013",
              "SlotDay": "Sunday",
              "SlotTime": "10:00"
          }, {
              "SlotID": 47002,
              "StaffID": 1,
              "BusinessID": 1,
              "SlotDate": "24/02/2013",
              "SlotDay": "Sunday",
              "SlotTime": "10:30"
          }]
      ]}
  }]
  }]
  }
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>        public ActionResult Index(DateTime start, string id = null)
      {
  
          var allids = Request.QueryString["id"];
  
          // split the input into anonymous objects containing staffid and businessid
          var staffids = from staffid in allids.Split(',').Select(x =&gt; x.Split('-'))
              select new { sid = int.Parse(staffid[0]), bid = int.Parse(staffid[1]) };
  
          // get the days you need
          var days = Enumerable.Range(0, 7).Select(x =&gt; start.AddDays(x));
  
          // create myDates
          int i = 0;
          var myDates = (from day in days
                         select new  KeyValuePair&lt;string, string&gt;(
                            String.Format("date{0}", i++),
                            day.ToShortDateString())).ToList();
          i = 0;
          myDates.AddRange(
                        (from day in days
                         select new  KeyValuePair&lt;string, string&gt;(
                            String.Format("dname{0}", i++),
                            day.DayOfWeek.ToString())).ToList());
          myDates.Add(new KeyValuePair&lt;string, string&gt;("ndate", days.First().AddDays(7).ToString("yyyy-MM-dd")));
          myDates.Add(new KeyValuePair&lt;string, string&gt;("pdate", days.First().AddDays(-7).ToString("yyyy-MM-dd")));
  
          // receive all the stored_procedures
          i = 0;
          var myStaff = from staff in staffids
                        select new KeyValuePair&lt;string, object&gt;(
                           String.Format("staff{0}", i++),
                           (from day in days
                            select db.Database.SqlQuery&lt;GetAvailableAppointments&gt;("EXEC SP_GetAvailableAppointments @StaffID, @BusinessID, @StartDate",
                              new SqlParameter("StaffID", staff.sid),
                              new SqlParameter("BusinessID", staff.bid),
                              new SqlParameter("StartDate", day))).ToList()
                       );
  
          return Json(new { myDates, myStaff }, JsonRequestBehavior.AllowGet);
  
      }
  </code></pre>
  
  <p>Any help would be appreciated :)</p>