Invalid Label Error When Eval JSON

Written by on Oct 25 2007

If you are getting an “invalid label” error when doing eval() on a json string, here is the solution:

You must do eval(‘(’ + jsonObj + ‘)’) to fix this. I know this seems really stupid, but http://www.json.org/js.html shows just this same example. I wrote a function to handle this:

function jeval(str){return eval(‘(’ + str + ‘)’)}

and then I call jeval() instead of eval();

Meet
Steven

Hi I'm Steven,

I wrote the article you're reading... I lead the developers, write music, used to race motorcycles, and help clients find the right features to build on their product.

Get Blog Updates