Skip to content

Instantly share code, notes, and snippets.

@banzeh
Created April 30, 2020 12:03
Show Gist options
  • Save banzeh/775303d7b91e1ac6e4bf18f8791d7079 to your computer and use it in GitHub Desktop.
Save banzeh/775303d7b91e1ac6e4bf18f8791d7079 to your computer and use it in GitHub Desktop.
Função em TS com Regex para validar JSON
public validateJSON(text: string): boolean {
return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + text + ')');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment