var str=`let str = {"parts":[{name: 'John'}],"total":1,}`; alert(str.replace(/,?(.)$/,'$1'));
var str=`let str = {"parts":[{name: 'John'}],"total":1}`; alert(str.replace(/,?(.)$/,'$1'));