After much effort, I have finally managed to format my data as valid JSON with the following Javascript code:
var roles = getSelectedRoles(); // returns an Array object
/* TODO: Explore better methods for incorporating roles into JSON data */
var rolesString = '["' + roles[0] + '"';
if (roles.length > 1)
for (var i = 1; i < roles.length; i++)
rolesString += ',"' + roles[i] + '"';
rolesString += ']';
var lid = $('#lid').val();
var json = '{ "id": "' + lid + '",
It's evident that constructing a JSON string in this manner by iterating through an Array is far from ideal. There must be a cleaner and more efficient way to include Array data within JSON.