George Bailey George Bailey - 1 year ago 57
Javascript Question

Is JSON.parse supported by all major browsers?

Possible Duplicate:

Browser-native JSON support (window.JSON)

Specifically, is
supported by IE7+, Firefox 2+, Chrome, Safari?

See: JSON in JavaScript

Answer Source

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:

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 both JSON.parse and JSON.stringify. Parsing uses a few regexes to defend against script injection attacks and then passes the result to eval. This isn't generally considered a very good idea.
  • json_parse.js: A recursive-descent parser that doesn't use eval.
  • json_parse_state.js: A state-machine parser that doesn't use eval.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download