Some day I wanted to check if the string is valid of JSON format. After some research I found the solution:

 * Function isJSON
 * Check if a string is JSON

    String.prototype.isJSON = function()
        return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(this.replace(/"(\\.|[^"\\])*"/g,'')));


You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *