#50286 [Opn->Bgs]: json_decode returns false when leading zeros aren't escaped with double quotes

From: Date: Tue, 24 Nov 2009 18:48:01 +0000
Subject: #50286 [Opn->Bgs]: json_decode returns false when leading zeros aren't escaped with double quotes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-145030@lists.php.net to get a copy of this message
ID: 50286 Updated by: rasmus@php.net Reported By: ygbr at me dot com -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: Linux Debian Lenny PHP Version: 5.3.1 New Comment: Then those Java implementations are broken. The JSON spec quite clearly states that if a number starts with a 0 then the only valid next character, if there is one, is a "." indicating a floating point value. File a bug against those and point them to http://json.org -Rasmus Previous Comments: ------------------------------------------------------------------------ [2009-11-24 18:44:14] ygbr at me dot com Description: ------------ When parsing a JSON Payload containing integers or floats with leading zeros as values which haven't been escaped using double quotes, json_decode() returns false. Even thought leading zeros are ( most of the times ) irrelevant for integers, the function should at least trim the zeros out and not fail the entire decoding process. JSON returned from some Java JSON generators come with integers containing leading zeros and not escaped by double quotes. Reproduce code: --------------- <?php $payload = <<<payload { "test" : 06 } payload; if(!$obj = json_decode($payload)) die("Problems on JSON Parsing the json_decode() function has returned false"); print_r($obj); Expected result: ---------------- stdClass Object ( [test] => 6 ) Actual result: -------------- Problems on JSON Parsing the json_decode() function has returned false ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50286&edit=1

« previous php.bugs (#145030) next »