Return to Snippet

Revision: 39725
at January 20, 2011 05:20 by jatubio


Initial Code
// Comprueba si una cadena es json o no.
	// 19/01/2011 Jatubio - http://webfreak.no/wp/2007/09/07/jsontest-for-mootools/
function is_json($string)
{
	return !empty($string) && is_string($string) && preg_match('/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/',$string);
}

Initial URL

                                

Initial Description
Check if a string it's json encoded using regular expressions

Thanks to Jens Anders Bakke for his mootools code published in webfreak.no

http://webfreak.no/wp/2007/09/07/jsontest-for-mootools/

Initial Title
Check if a string it's json encoded using regular expressions

Initial Tags
json

Initial Language
PHP