title: Converting JSON array to JSON Object
body: <p>I am trying to convert a JSON array to an Object. This is a hacked way but good enough for my purpose.</p>
  
  <p>Basically I am writing a method to get this</p>
  
  <pre><code>var data = [{
      "MonthYearShortName": "Sep-13",
          "TotalCustomers": 1905.0,
          "Aquisition": 317.0,
          "Attrition": 9.0
  }, {
      "MonthYearShortName": "FY-14",
          "TotalCustomers": 2158.0,
          "Aquisition": 401.0,
          "Attrition": 15.0909090909091
  }]
  </code></pre>
  
  <p>into something like this</p>
  
  <pre><code>data = [{
      key: 'Attrition',
      color: '#d62728',
      values: [{
          "label": "Sep-13",
          "value": 9
      }, {
          "label": "FY-14",
              "value": 15.0909090909091
      }]
  },
  
  {
      key: 'Total Customer',
      color: '#1f77b4',
      values: [{
          "label": "Sep-13",
          "value": 1905
      }, {
          "label": "FY-14",
          "value": 2158
      }]
  },
  
  {
      key: 'Aquisition',
      color: '#1f7774',
      values: [{
           "label": "Sep-13",
           "value": 317
      }, {
              "label": "FY-14",
              "value": 401
      }]
  }
  
  ];
  </code></pre>
  
  <p>The colors will be static for now. I will be handling it later.</p>
  
  <p>Now getting to my hacked way of getting this (this is crude I know)</p>
  
  <p>I tried something like this to just get the attrition out</p>
  
  <pre><code> var data = @"[{""MonthYearShortName"": ""Sep-13"",""TotalCustomers"": 1905.0,""Aquisition"": 317.0,""Attrition"": 9.0}, {""MonthYearShortName"": ""FY-14"",""TotalCustomers"": 2158.0,""Aquisition"": 401.0,""Attrition"": 15.0909090909091}]";
                  JArray a = JArray.Parse(data);
  
                  var label1 = a[0]["MonthYearShortName"].ToString();
                  var label2 = a[1]["MonthYearShortName"].ToString();
                  var totalCustomer1 = a[0]["TotalCustomers"].ToString();
                  var totalCustomer2 = a[1]["TotalCustomers"].ToString();
                  var aquisition1 = a[0]["Aquisition"].ToString();
                  var aquisition2 = a[1]["Aquisition"].ToString();
                  var attrition1 = a[0]["Attrition"].ToString();
                  var attrition2 = a[1]["Attrition"].ToString();
  JObject rss1 =
                  new JObject(
                      new JProperty("channel",
                          new JObject(
                              new JProperty("Key", "Attrition"),
                              new JProperty("color", "#d62728"),
                              new JProperty("values",
                                  new JArray(
                                      from p in a
                                      select new JObject(
                                          new JProperty("label", a[0]["MonthYearShortName"].ToString()),
                                          new JProperty("value", attrition1),
                                          new JProperty("label", a[1]["MonthYearShortName"].ToString()),
                                          new JProperty("value", attrition2)))))));
  </code></pre>
  
  <p>When I tried this I get a </p>
  
  <pre><code>Can not add property label to Newtonsoft.Json.Linq.JObject. Property with the same name already exists on object.
  </code></pre>
  
  <p>Now if someone can suggest a cleaner way (as I cant think of any right now), I would be greatful or if my code could be corrected, that would be helpful.</p>
  
  <p>Thanks</p>