jQuery.parseJSON
and JSON.parse
are two functions that perform the same task. If the jQuery library is already loaded, would using jQuery.parseJSON
be better than using JSON.parse
, in terms of performance?
If yes, why? If no, why not?
If yes, why? If no, why not? |
|||||
|
Here is an extract from jQuery 1.9.1:
As you can see, jQuery will use the native So yes, you should definitely use |
|||||||||||||||||
|
thus it means that jQuery provides a JSON parser if no native implementation exists on the browser. here's a comparison chart of browsers that have (and don't have) JSON functionality |
|||||||||
|
I don't know about performance, but it's definitely safer to use the jQuery method because some browsers like ie7 and lower might not have any JSON functionalities natively. |
|||||||||||||
|
JSON.parse() is natively available on some browsers, not on others, so it's safer to use a library. The JQuery implementation works well, as other respondents have noted. There's also Douglas Crockford's JSON library, which uses the native implementation if available. The JSON library has the advantage that it has a method to turn a JavaScript object into a JSON string, which is missing from jQuery at the moment.. |
|||
|
This should improve this thread: http://caniuse.com/#feat=json The JSON object has suppport in every single browser nowadays, so you should opt in for it instead of using jQuery's parseJSON, which I repeat, nowadays is unnecessary. You can also search for this alias appearances at the repository, on github: https://github.com/jquery/jquery/search?utf8=%E2%9C%93&q=parseJSON You should only use the jQuery's version if you're going to provide support for very, very, very old browsers. Hope to help this old thread for people who have fallen here recently. Thumbs up if you agree. Best regards to all of you. |
|||
|