I get that JSON.parse() prevents an attacker from injecting javascript into the response since a JSON parser is just a text parser, not a script parser so please don\'t close th
Yes, it is really safer. Every precaution you do not take is a set of potential exploits you don't prevent.
An attacker might be able to have some control over your server's output without being able to change it entirely. Nobody's suggesting it's a magic bullet, but it's potentially faster and you're not creating a potential vulnerability that could come back and hurt you.
Maybe someone running your server is having a bad day, and does something silly like constructing JSON by concatenating unsanitized user input:
If you're using JSON.parse
, the worst they can do is shove a large object into your memory. If you're using eval
they can hijack everything.