#41505 [Opn->Asn]: json_encode() improperly encodes PHP arrays with an empty string array key
| From: | iliaa@php.net | Date: | Sat, 26 May 2007 20:24:20 +0000 |
| Subject: | #41505 [Opn->Asn]: json_encode() improperly encodes PHP arrays with an empty string array key | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-113049@lists.php.net to get a copy of this message | ||
ID: 41505
Updated by: iliaa@php.net
Reported By: jmorrow at jessejmorrow dot com
-Status: Open
+Status: Assigned
Bug Type: Unknown/Other Function
Operating System: OS X
PHP Version: 5.2.2
-Assigned To:
+Assigned To: iliaa
Previous Comments:
------------------------------------------------------------------------
[2007-05-26 07:33:10] jmorrow at jessejmorrow dot com
Description:
------------
The json_encode() function completely ignores, and thus does not
encode,
PHP array entries with an array key that is an empty string: array
(""=>"value");
Empty string array keys and object properties are totally valid PHP and
JSON respectively - they should encode/decode as such.
This, along with the corresponding json_decode() bug of a similar
nature
(41504), are show stoppers for me as I need JSON encode/decode to be
rock solid and consistent.
Thanks for looking into this :-)
Reproduce code:
---------------
1) var_dump(json_encode(array(""=>"value")));
2) var_dump(json_encode(array(""=>"value1",
"key2"=>"value2")));
Expected result:
----------------
1) string(15) "{"":"value"}"
2) string(17) "{"":"value1", "key2":"value2"}"
Actual result:
--------------
1) string(2) "{}"
2) string(17) "{"key2":"value2"}"
In both cases the array entry with the empty string key is missing.
This might be addressed by Bug #41034, but may very well be a different
bug.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41505&edit=1