Safely turning a JSON string into an object

Given a string of JSON data, how can you safely turn that string into a JavaScript object?

Obviously you can do this unsafely with something like...

var obj = eval("(" + json + ")");

...but that leaves us vulnerable to the json string containing other code, which it seems very dangerous to simply eval.



Is a pure JavaScript approach so long as you can require a reasonably modern browser.

See also

Answer is