|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41505 json_encode() improperly encodes PHP arrays with an empty string array key
Submitted: 2007-05-26 07:33 UTC Modified: 2009-11-13 14:52 UTC
From: jmorrow at jessejmorrow dot com Assigned: iliaa (profile)
Status: Closed Package: JSON related
PHP Version: 5.2.2 OS: OS X
Private report: No CVE-ID: None
 [2007-05-26 07:33 UTC] jmorrow at jessejmorrow dot com
The json_encode() function completely ignores, and thus does not encode, 
PHP array entries with an array key that is an empty string: array

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 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-27 16:32 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 17:01:29 2024 UTC