note 85285 added to function.json-decode

From: Date: Sat, 23 Aug 2008 18:59:21 +0000
Subject: note 85285 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-143773@lists.php.net to get a copy of this message
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 ---- Server IP: 209.41.74.194 Probable Submitter: 66.170.10.66 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/85285 Del: integrated -- https://master.php.net/note/delete/85285/integrated Del: useless -- https://master.php.net/note/delete/85285/useless Del: bad code -- https://master.php.net/note/delete/85285/bad+code Del: spam -- https://master.php.net/note/delete/85285/spam Del: non-english -- https://master.php.net/note/delete/85285/non-english Del: in docs -- https://master.php.net/note/delete/85285/in+docs Del: other reasons-- https://master.php.net/note/delete/85285 Reject -- https://master.php.net/note/reject/85285 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143773) next »