<p>Given a string of JSON data, how can I safely turn that string into a JavaScript object?</p>

<p>Obviously I can do this unsafely with something like:</p>

<pre><code>var obj = eval("(" + json + ')');
</code></pre>

<p>but that leaves me vulnerable to the JSON string containing other code, which it seems very dangerous to simply eval.</p>

I'm not sure about other ways to do it but here's how you do it in
Prototype (JSON tutorial)
.
```
```
new Ajax.Request('/some_url', {
  method:'get',
  requestHeaders: {Accept: 'application/json'},
  onSuccess: function(transport){
    var json = transport.responseText.evalJSON(true);
  }
});
```
```
Calling
```
evalJSON()
```
with true as the argument sanitizes the incoming string.