note 85285 deleted from function.json-decode by googleguy
| From: | googleguy@php.net | Date: | Fri, 30 Nov 2012 05:54:17 +0000 |
| Subject: | note 85285 deleted from function.json-decode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192230@lists.php.net to get a copy of this message | ||
Note Submitter: soapergem at gmail dot com
----
There have been a couple of comments now alerting us to the fact that certain expressions that are
valid JavaScript code are not permitted within json_decode. However, keep in mind that JSON is
***not*** JavaScript, but instead just a subset of JavaScript. As far as I can tell, this function
is only allowing whatever is explicitly outlined in RFC 4627, the JSON spec.
For instance, ganswijk, the reason you can't use single quotes to enclose strings is because
the spec makes no mention of allowing single quotes (and therefore they are not allowed). And the
issue of adding an extra comma at the end of an array is likewise not technically permitted in
strict JSON, even though it will work in JavaScript.
And xris, while the example you provided with an unenclosed string key within an object is valid
JavaScript, JavaScript != JSON. If you read it closely, you'll see that the JSON spec clearly
does not allow this. All JSON object keys must be enclosed in double-quotes.
Basically, if there's ever any question for what is permitted, just read the JSON spec: http://tools.ietf.org/html/rfc4627