Voici le code que j'utilise pour faire cela : 
//~ [FUNCTION]
function __json_encode($mVar,$fnCallback="stripcslashes") {
    return preg_replace_callback('#"[ ]{0,}function[ ]{0,}\([^)$]{0,}\)[ ]{0,}\{[ ]{0,}(?(?![ ]{0,}}[ ]{0,}").){0,}[ ]{0,}\}[ ]{0,}"([(?,")|(?\}{0,}$)]{0,})#si', 
        function ($aRes) use ($fnCallback) { 
            for($aRes[0]=substr($aRes[0],1),$sOut="",$i=0,$iOpen=0,$iClose=0;$i<= strlen($aRes[0]) && $sOut.= substr($aRes[0],$i,1);$i++) 
                if (substr($aRes[0],$i,1) == "{") $iOpen++;
                else if (substr($aRes[0],$i,1) == "}" AND $iOpen == ++$iClose) break;
            return is_callable($fnCallback) ? $fnCallback($sOut).$aRes[1] : $sOut.$aRes[1]; 
        },json_encode($mVar)
    );
}
//~ [TEST]
print "<script>\n";
print sprintf(
    "\tvar oTest = %s;",
    __json_encode(
        array( 
            "Numeric"=>1,
            "string"=>"hello world !",
            "myFunction"=>"function(test) {  if (test==1) { alert('myFunction(1)'); return true; } else return false; }",
            "myObject"=>array(
                "Numeric"=>1,
                "string"=>"hello world !",
                "myFunction"=>"function(test) {  alert('myFunction(1)'); return true; }")
        )
    )
);
print "\n\tif (oTest.myFunction(1) == false) alert('myFunction(0)');";
print "\n\tif (oTest.myObject.myFunction(0) == false) alert('myFunction(0)');";
print "\n</script>";
Voici le résultat : 
    <script>
        var oTest = {
            "Numeric":1,
            "string":"hello world !",
            "myFunction":function(test) {  if (test==1) { alert('myFunction(1)'); return true; } else return false; },
            "myObject":{
                "Numeric":1,
                "string":"hello world !",
                "myFunction":function(test) {  alert('myFunction(1)'); return true; }
            }
        };
        if (oTest.myFunction(0) == false) alert('myFunction(0)');
        if (oTest.myObject.myFunction(1) == false) alert('myFunction(0)');
    </script>
Cdt.