Is JSON.parse supported by all major browsers?
Solution 1
The answer in 2013 (and later)
Is JSON.parse supported by all major browsers?
Pretty much, yes (source). Even IE8 has it (provided you're not in IE7 emulation mode). If you need to support IE7 and earlier, read on.
The original answer from 2011
No, older browsers (IE7 for instance) mostly don't have it. (More: http://caniuse.com/#search=JSON.parse)
However, just a small script is all you need. The inventor of JSON, Douglas Crockford, has no fewer than three for you to choose from on his Github page:
-
json2.js
: Provides bothJSON.parse
andJSON.stringify
. Parsing uses a few regexes to defend against script injection attacks and then passes the result toeval
. This isn't generally considered a very good idea. -
json_parse.js
: A recursive-descent parser that doesn't useeval
. -
json_parse_state.js
: A state-machine parser that doesn't useeval
.
Use what suits you. :-)
Just about any major library (like jQuery, Prototype, YUI, Closure, or any of several others) will also provide JSON parsing, although in some cases it may well be a thin veneer on eval
.
Solution 2
I am afraid not. You can however use json2 script written by Douglas Crockford.
Here is what John Resig (creator of jQuery) has to say about it:
JSON2.js - Late last year Crockford quietly released a new version of his JSON API that replaced his existing API. The important difference was that it used a single base object (JSON) instead of extending all native object prototypes (booo!).
http://ejohn.org/blog/the-state-of-json/
You can download json2.js here :)
![700 Software](https://i.stack.imgur.com/s77Za.jpg?s=256&g=1)
700 Software
Join 700.social ! A happy medium between Facebook and Gab. :) The name is too long but the domain looks good. Also, Software Development / Consulting (423) 802-8971 700software.com old username: George Bailey (but now I use my real name) http://www.google.com/images?q=George+Bailey
Updated on June 08, 2022Comments
-
700 Software about 2 years
Possible Duplicate:
Browser-native JSON support (window.JSON)Specifically, is
JSON.parse(...)
supported by IE7+, Firefox 2+, Chrome, Safari?See: JSON in JavaScript