title: Serialize c# array of strings to JSON array
body: <p>i have the following code in my _Layout.cshtml file.  The idea is that in my javascript code some items about the security are filled in.  LoggedIn and username are obviously no problem, but the way the roles are put in the javascript is wrong.  The Roles is simply a string[] (that should become a JSON array.  </p>
  
  <p>But it shows as a '[&amp; quot;user&amp; quot;,&amp; quot;&#39;admin&amp; quot;]' which obviously is not a valid JSON array.  Any ideas how i can convert my string array to a valid JSON array?  My code of the RolesArray is added below.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function () {
          require(['jquery','config', 'security'],
                  function ($, config, security) {
  
                  security.items.loggedIn = '@Request.IsAuthenticated';
                  security.items.Username = '@User.Identity.Name';
  
                  var one = '@((MyIdentity)User.Identity).RolesArray'
                  $(document).trigger("security_changed");
             });
      });
  &lt;/script&gt;
  
  
  public String[] RolesArray   
  {
      get
      {
          var two = Roles.ToArray();
          return two;        
      }
  }
  </code></pre>