Eval() = Unexpected token : error

Tuizi picture Tuizi · Nov 2, 2011 · Viewed 33.8k times · Source

I tried this simple JavaScript code:

eval('{"Topics":["toto","tata","titi"]}')

In the Chrome console, for example, this returns

SyntaxError: Unexpected token :

I tried the JSON on JSONLint and it's valid.

Do you see the bug?

Answer

Martin Varta picture Martin Varta · Jan 17, 2013

You have to write like this

eval('('+stingJson+')' );

to convert an string to Object

Hope I help!