Skip to main content

creating json object with variables

if you need double quoted JSON use JSON.stringify( object)

var $items = $('#firstName, #lastName,#phoneNumber,#address ')
var obj = {}
$items.each(function() {
    obj[this.id] = $(this).val();
})

var json= JSON.stringify( obj); 

Ref : https://stackoverflow.com/questions/12979335/creating-json-object-with-variables

Comments