Skip to content

Instantly share code, notes, and snippets.

@bga
Created April 30, 2010 05:00
Show Gist options
  • Save bga/384769 to your computer and use it in GitHub Desktop.
Save bga/384769 to your computer and use it in GitHub Desktop.
var
parseAcceptRE = new RegExp(/[{}\[\]:,]+|\"([^\\\"]*?\\.)*[^\"]*?\"|[+\-]?\d+(?:\.\d+)?(?:[eE][+\-]?\d+)?|true|false|null|\s+/g),
// var name at begin
// keywords, which can be written space separeted
// specific keywords
// operator and var name or object
// property access (but not number point delimiter)
// property access via square bracket (but not array declaration)
unsafeCharsRE = new RegExp(/^[a-zA-Z_\$\/]|var|new|instanceof|var|function|typeof|(?![\[,:]\[)[\+\-\*\/%\^&\|~\!\=<>\:,\[\(]\s*[a-zA-Z_\$\/\[]|\.[a-zA-Z_\$]|[\w\$\/\)\]]\s*\[/);
JSON_OBJ_NAME.parse = function(str)
{
if(unsafeCharsRE.test(str))
{
str = '//' + str.replace(parseAcceptRE, '\n$&//') + '\n';
console.log(str);
}
return eval('(' + str + ')');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment