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?
Chrome
{"label":1111} - SyntaxError: Unexpected token :
{label:1111} - Works
Firefox
{"label":1111} - SyntaxError: invalid label
{label:1111} - Works
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 the label: 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With