#50166 [Opn->Bgs]: json_encode returns wrong brackets for empty array

From: Date: Fri, 13 Nov 2009 14:56:24 +0000
Subject: #50166 [Opn->Bgs]: json_encode returns wrong brackets for empty array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-144584@lists.php.net to get a copy of this message
ID: 50166 Updated by: jani@php.net Reported By: dumpbox at mail dot ru -Status: Open +Status: Bogus Bug Type: JSON related Operating System: Windows XP PHP Version: 5.2.11 New Comment: Yes, that would be an array in JSON. Please check http://www.json.org/ for the syntax. No bug here. (and yes, assoc arrays do end up as objects..) Like this: [jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo" => "bar")));' string(13) "{"foo":"bar"}" [jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo", "bar")));' string(13) "["foo","bar"]" No bug here. Previous Comments: ------------------------------------------------------------------------ [2009-11-13 13:59:41] dumpbox at mail dot ru Description: ------------ By default json object starts with "{" and ends with "}" Error occurs when user attempt encode empty array. Reproduce code: --------------- echo json_encode(array()); Expected result: ---------------- {} Actual result: -------------- [] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50166&edit=1

« previous php.bugs (#144584) next »