I need to convert a string into a JSON object so that I can post it using AJAX. As of now, all the answers I could find were converting it to javascript objects due to which there were no double quotes on the 'keys' and had double quotes only on the values. I have searched a lot, but almost all the answers convert it to a JS object, and the REST endpoint will only accept JSON object. Please help.
I have a string in this format:
{"subject":"school,","description":"top10,","classsize":"35"}
Function to get form data as JSON string
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
and then I use JSON.stringify on the form data.
{"subject":"school,","description":"top10,","classsize":"35"}is valid JSON.