Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created April 29, 2009 18:19
Show Gist options
  • Save lsmith/103949 to your computer and use it in GitHub Desktop.
Save lsmith/103949 to your computer and use it in GitHub Desktop.
YUI.add('json-trusted', function (Y) {
function evalWrapper(str) { return eval('('+str+')'); }
Y.namespace('TrustedJSON').parse =
(Object.prototype.toString.call(window.JSON) === '[object JSON]') ?
function (str) {
return /^\s*(?:"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)\s*$/.test(str) ?
evalWrapper(str) : // FF3.5 Native does not support non-object/array input
JSON.parse(str);
} :
evalWrapper;
}, '@VERSION@');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment