title: Convert C# List of object to JavaScript array of objects
body: <p>I am using jQueryUI's <a href="http://api.jqueryui.com/autocomplete/#option-source" rel="noreferrer">autocomplete</a> to allow the search of users. The documentation states that I am able to use an array for the source of the data in the following format: <code>[ { label: "Choice1", value: "value1" }, ... ]</code></p>
  
  <p>I have a base class that provides a list of unique <code>Users</code> which is inherited by my view-model. The view model has the following function:</p>
  
  <pre><code>public List&lt;TestJson&gt; GetUsers()
  {
      return AvailableUsers
          .Select(u =&gt; new TestJson
              {
                  Label = u.LastName + ", " + u.FirstName + "(" + u.UserId + ")",
                  Value = u.UserId
              }).ToList();
  }
  
  public class TestJson
  {
      public string Label { set; get; }
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>In my view, I use the above like so:</p>
  
  <pre><code>var userNameList = @Html.Raw(Json.Encode(Model.GetUsers()));
  
  $("#UserName").autocomplete({
      source:userNameList 
  });
  </code></pre>
  
  <p>Turns out <code>userNameList</code> is showing up like this:</p>
  
  <pre><code>[ { "Label": "Choice1", "Value": "value1" }, ... ]
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>[ { label: "Choice1", value: "value1" }, ... ]
  </code></pre>
  
  <p>How can I get my array to show in the correct format?</p>
  
  <p><strong>EDIT:</strong> Based on input from comments, I have verified that both those formats are indeed functionally equivalent. I did a little more testing and it turns out that <code>label</code> and <code>value</code> are case sensitive. Changing my members to lower case seems to do the trick, but I don't feel that solution is the best. Any suggestions on how to change the string on the left side of the : (what is this called?) to lowercase?</p>