Here is a string:
"{aa:function(){},bb:document.body}"
JSON.parse doesn't work for this,how to convert it to JS object?
You could use eval with a prepended assingment.
Caveat: Why is using the JavaScript eval function a bad idea?
var string = "{aa:function(){},bb:document.body}",
object;
eval('object = ' + string);
console.log(object);
var obj = eval('(' + string + ')'). (Using parantheses so that the object is not parsed as a block)An option in this case could be to use new Function().
It is less evil than eval(), and here is an answer with an explanation about their difference:
Stack snippet
var string = "{aa:function(){},bb:document.body}",
object;
object = new Function( 'return (' + string + ')' )();
console.log(object);
eval, if you are sure about the content.