Skip to content

Instantly share code, notes, and snippets.

@cms
Created October 6, 2010 18:09
Show Gist options
  • Save cms/613812 to your computer and use it in GitHub Desktop.
Save cms/613812 to your computer and use it in GitHub Desktop.
JSON.stringify broken on Firefox
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