It seems there are different standards out there on labels for JSON, some want quotes around JSON object labels, some do not. Can someone tell me what the standard is?
Quotes are bad camp
Chrome
{"label":1111} – SyntaxError: Unexpected token :
{label:1111} – Works
Firefox
{"label":1111} – SyntaxError: invalid label
{label:1111} – Works
Quotes are good camp
JSLint
{"video_id":1111} – JSON: good.
{video_id:1111} – JSON: bad. Expected a string and instead saw ‘video_id’
PHP
echo json_encode(array('label' => 1111));
{"label":1111}
The standard is to parse JSON as JSON.
The JSON language (unlike Javascript) always requires all property names to be surrounded by double-quotes.
Your syntax errors come from trying to parse JSON as Javascript statements. The
{}is parsed as a statement block, and thelabel:is parsed as a GOTO target.Since statement labels cannot have quotes, this results in a syntax error.
If you wrap the JSON literals in parentheses to force Javascript to parse them as expressions, you won’t get that error.