title: How to put an Array object into JSON?
body: <p>I have written the following Javascript code.  It's the best I could do to get my data formatted as valid JSON:</p>
  
  <pre><code>var roles = getSelectedRoles(); // returns an Array object
  
  /* TODO: Find a better way to get the roles into my JSON data */
  var rolesString = '["' + roles[0] + '"';
  if (roles.length &gt; 1)
      for (var i = 1; i &lt; roles.length; i++)
          rolesString += ',"' + roles[i] + '"';
  rolesString += ']';                        
  
  var lid = $('#lid').val();
  
  var json = '{ "id": "' + lid + '", "roles":' + rolesString + '}';
  </code></pre>
  
  <p>As you can see, I am building my JSON with string concatenation looping thru my Array object.  This is so ugly and it seems like there ought to be a clean way of inserting my Array data into my JSON.</p>