Skip to main content
edited tags
Link
Kamil Kiełczewski
  • 93.6k
  • 34
  • 401
  • 375
edited for readability
Source Link
the Tin Man
  • 160.9k
  • 44
  • 222
  • 308

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

Obviously youI can do this unsafely with something like...:

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

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

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.

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

Obviously I can do this unsafely with something like:

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

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

Question Protected by cassiomolin
Source Link
Matt Sheppard
  • 118.3k
  • 46
  • 115
  • 134
Loading