Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JSON.parse supported by all major browsers? [duplicate]

Possible Duplicate:
Browser-native JSON support (window.JSON)

Specifically, is JSON.parse(...) supported by IE7+, Firefox 2+, Chrome, Safari?

See: JSON in JavaScript

like image 649
700 Software Avatar asked Feb 05 '11 18:02

700 Software


People also ask

Is JSON supported by all browsers?

All modern browsers support native JSON encoding/decoding (Internet Explorer 8+, Firefox 3.1+, Safari 4+, and Chrome 3+). Basically, JSON. parse(str) will parse the JSON string in str and return an object, and JSON. stringify(obj) will return the JSON representation of the object obj .

What is JSON parsing?

JSON parsing is the process of converting a JSON object in text format to a Javascript object that can be used inside a program. In Javascript, the standard way to do this is by using the method JSON. parse() , as the Javascript standard specifies.

Is JSON parse insecure?

The built-in functions (JSON. parse()) are not vulnerable so you can use them safely.

How does JSON parse work?

How Does JSON Parse Work? The JSON parse function takes data that's in a text format and then converts it into JavaScript. Usually, these take the form of JavaScript objects, but the parse function can be used directly on arrays as well.


1 Answers

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 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.

like image 141
T.J. Crowder Avatar answered Sep 20 '22 08:09

T.J. Crowder