1
0
Fork 0

Detect and report common mistakes in json syntax, refs #36

pull/48/head
Jordi Boggiano 2011-10-02 21:14:00 +02:00
parent cad0967788
commit 1a9de17a88
1 changed files with 5 additions and 0 deletions

View File

@ -107,6 +107,11 @@ class JsonFile
break;
case JSON_ERROR_SYNTAX:
$msg = 'Syntax error';
if (preg_match('#["}\]]\s*(,)\s*\}#', $json, $match, PREG_OFFSET_CAPTURE)) {
$msg .= ', extra comma on line '.(substr_count(substr($json, 0, $match[1][1]), "\n")+1);
} elseif (preg_match('#(\'.+?\' *:|: *\'.+?\')#', $json, $match, PREG_OFFSET_CAPTURE)) {
$msg .= ', use double quotes (") instead of single quotes (\') on line '.(substr_count(substr($json, 0, $match[1][1]), "\n")+1);
}
break;
case JSON_ERROR_UTF8:
$msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';