views:

1828

answers:

1

I have some JS that runs fine in FF and IE but in Chrome I see the following error:

uncaught exception ReferenceError: JSON is not defined

I presume I need to include something but I'm not sure what. Help? Also, any clue why this might work on IE/FF but not Chrome?

Btw, I'm using JSON.stringify() in my script.

+5  A: 

The JSON object is not yet part of the standard IIRC, but is expected to be soon. In the meantime, browsers are free to implement it at will, and that's probably what you are seeing here.

Your best bet is to get a separate library that does the same thing and use it for the meantime until native implementations are more widespread. You can find a very good one here (Link at the bottom).

Toji
Specifically, I believe only FF3.5 and IE8 currently implement it.
Ben Blank
So for FF3.5 and IE8, would the built-in implementation win or would the included js be used? Just curious how it works for JS in general...
psychotik
The js file sniffs for existing window.JSON members and will leave them in place if present. (Could be native, could have been put there by another library.)
bobince
Chromium builds have also had native JSON support for a while.
Eli Grey