(function( $ ) { $.fn.get_json_from_class = function() { var $this = $(this); // Do your awesome plugin stuff here var cname = $this.attr('class'); if (cname){ if (matches = cname.match(/(\{.*\})/) ){ var jsonstr = decodeURIComponent(matches[1]); var string = jsonstr; if (true && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) { return null; alert('Scubbly Widget error. Bad Parameters.'); } try{ var dataobj = eval( '(' + decodeURIComponent(matches[1]) + ')'); }catch(err){ return null; alert('invalid JSON in class'); } return dataobj; } else { return {}; } } else { return {}; } }; })( jQuery );