JSON.parse() vs eval()

07 Mar

Hi folks,

Here are some important point which will give the clear differentiation about why we go for JSON.parse() instead eval() method.

1. JSON is a subset of Javascript and json.parse() just parses JSON whereas eval would leave the door open to all javascript expressions.

2. All JSON.parse() implementations most likely use eval().

3. Not all browsers have native JSON support so there will be times where we need to use eval() to the JSON string.
Use JSON parser from or as that makes everything easy for us.
eval() is an evil but against some browsers its a necessary evil but where you can avoid it,do so.

4. If we parse the JSON with eval, we are allowing the string being parsed to contain absolutely anything, so instead of just being a set of data, you could find yourself executing function calls, or whatever also JSON’s parse accepts an aditional parameter, reviver, that lets you specify how to deal with certain values, such as datetimes

5. The eval function is very fast. However, it can compile and execute any JavaScript program, so there can be security issues. The use of eval is indicated when the source is trusted and competent. It is much safer to use a JSON parser.

Reference URLs

Happy Learning!.

Get glued to know more updates.

Have a nice day 🙂

Leave a comment

Posted by on March 7, 2013 in Uncategorized


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: