pass function in json and execute
Yes, you can convert a function to a string with it's toString()
method.
Here's an example to show converting a function to a string and back to a function:
var myfunc = function () {
alert('It works!');
}
var as_string = myfunc.toString();
as_string = as_string.replace('It works', 'It really works');
var as_func = eval('(' + as_string + ')');
as_func();
Yes, you can. There are tons of ways to do it.
And there is no need to use the "evil" eval function (please yahoogle why it should be avoided) as pointed out here: http://javascript.about.com/library/bleval.htm
var tmpFunc = new Function(codeToRun);
tmpFunc();
Whether it was JSON at any stage should be irrelevant.