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?
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.
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.
Use the JavaScript function JSON. stringify() to convert it into a string. const myJSON = JSON. stringify(obj);
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With