title: javascript eval and object evaluation
body: <p>I have a part of a debugging framework that needs to be able to run time eval objects.</p>
  
  <p>Specifically, if I have a string like this <code>"{a: 1, b:2}"</code> it needs to evaluate it into an object with members <code>a</code> and <code>b</code> with those values. However, if I do <code>eval("{a: 1, b:2}")</code> it seems to evaluate it as a statement, and says something about an illegal label.</p>
  
  <p>I have hacked it so that it evaluates like this:</p>
  
  <pre><code>eval("var x=" + str + "; x;");
  </code></pre>
  
  <p>which seems to work, but seems like a horrible hack. Any suggestions on how to do this better?</p>
  
  <p>(BTW, I am aware of the dangers of eval, but this is part of a debugging framework that will not be seen by actual users.)</p>