I think it depends on your library. If you're using Prototype.js, then you can just call toJSON()
on the object, and then evalJSON()
the result.
//ex:
var foo = {"foo":12, "bar":[ 1, 2, 3 ] };
var bar = foo.toJSON().evalJSON();
alert( bar.bar ); // 1, 2, 3
If you do decide to use a custom function to accomplish this, I would recommend that it has allowances for Arrays, which you can clone using splice(), and other values which don't pass by reference natively (say, Booleans). These may complicate your functions a little, but they turn string look-ups to boolean evaluations. This is a case where more is faster.