JSON.stringify and JSON.parse not working in IE9?
52,259
Solution 1
why do you want to depend on the browser having the object instead just include the script file by Douglas Crockford.. You can find the minifed file here: http://www.json.org/js.html
Once imported you dont have to worry abt the method existing in a browser.
Solution 2
JSON.stringify
starts with a lower-case s
. Both stringify
and parse
are available in IE8+, but only in standards mode.
Prepend your document with <!DOCTYPE html>
if you're currently using quirks mode. Also, watch the capitalization of the JavaScript methods you call - all built-in ones start with a lower-case character.
Author by
saurabh ranu
Updated on July 05, 2022Comments
-
saurabh ranu almost 2 years
I'm using
JSON.Stringify
andJSON.parse
everywhere and it works fine with Firefox. It's working no more with IE9 nor does it work in IE8. What can I do? -
rlorenzo over 12 yearsIn addition, watch out if you're developing locally against a localhost address. A Windows Update to IE9 a few weeks ago caused it to begin automatically using compatibility mode for some localhost addresses, which can result in JSON.parse/stringify suddenly not being available even when your markup shouldn't have triggered quirks mode.
-
saurabh ranu over 12 yearsLooks better idea to me but which file i should add. There are a lot of files github.com/douglascrockford/JSON-js
-
Baz1nga over 12 yearsUse json2.js. That's the latest one.. Get the minified 1 if u can
-
Baz1nga over 12 yearsNothing special just a file with no spaces returns and minified variable names etc to reduce the file size.. Google bat us minification and u will find what it is.. If thud minified file isnt there pickup json2.js and u can think of minifying it if u want later
-
saurabh ranu over 12 yearsi have something already like <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
blong over 12 yearsWhen I started using
JSON.stringify
I was surprised to find it built into the browser (Firefox) even though I was sure it wouldn't work in IE8. I forgot to test in IE8 and sure enough, my app didn't work once I tried it there. Thanks for the helpful solution! -
Maksym Kozlenko over 11 yearsI would suggest to load json.org conditionally only if browser does not support JSON object navively by checking if window.JSON is defined. Otherwise you increase an number of downloaded JS files
-
ClearCloud8 almost 11 yearsMight the json2.js run slower than what is natively supported in IE10 as well? (another reason to conditionally load it, rather than always loading?)