Created
October 6, 2010 18:09
-
-
Save cms/613812 to your computer and use it in GitHub Desktop.
JSON.stringify broken on Firefox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj = { foo: function () { return "bar"; } }; | |
var jsonString = JSON.stringify(obj, function (key, value) { | |
if (typeof value == 'function') { | |
return value(); | |
} | |
return value; | |
}); | |
// Firefox <= 3.6, produces invalid JSON: '{"foo":}' | |
// Fortunately, this has been fixed on latest Firefox 4 builds | |
try { | |
obj = JSON.parse(jsonString); | |
} catch (e) { | |
console.log(jsonString, e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment