Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JSON.stringify() supported by IE 8?

Tags:

javascript

I need to use:

JSON.stringify() 

which should be supported by Chrome, Safari, and Firefox. I think IE8 also has support for the JSON object. I think IE7 and 6 do not, so I'm doing this:

<!--[if lt IE 8]>     <script src="http://www.json.org/json2.js"></script> <![endif]--> 

so, I think this will import the external JavaScript only if IE6 & 7. I looked at the URL where the script is hosted, they are including only if the IE version is less than 9:

http://code.google.com/p/html5shiv/ <!--[if lt IE 9]>     <script src="http://www.json.org/json2.js"></script> <![endif]--> 

so should I be including this for IE 8 too?

like image 460
user246114 Avatar asked Jul 24 '10 20:07

user246114


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.

What is JSON Stringify () method?

The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

How do I get JSON Stringify?

Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);

Do you need JSON for Stringify?

The JSON. stringify() method in Javascript is used to create a JSON string out of it. While developing an application using JavaScript, many times it is needed to serialize the data to strings for storing the data into a database or for sending the data to an API or web server.


1 Answers

To answer the question in the title directly, yes IE8 supports JSON.stringify() natively.

IE8 is the first version of IE to get this support, and the functionality is explained in detail by the dev team here: http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx

The answer the second part of the question, yes you would need to include alternate functionality for IE6/IE7. Something like Modernizr can make it easy to check this.

Also note if the user is in Compatibility View in IE8, the JSON object will not be available.

like image 156
whitneyland Avatar answered Sep 20 '22 15:09

whitneyland