#50867 [Opn->Bgs]: json_encode can't handle empty string keys
| From: | jani@php.net | Date: | Thu, 28 Jan 2010 08:25:30 +0000 |
| Subject: | #50867 [Opn->Bgs]: json_encode can't handle empty string keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147020@lists.php.net to get a copy of this message | ||
ID: 50867
Updated by: jani@php.net
Reported By: r at rcrowley dot org
-Status: Open
+Status: Bogus
Bug Type: JSON related
Operating System: Linux
PHP Version: 5.3.1
New Comment:
It can not work in PHP since you can not have empty object property
name.
Previous Comments:
------------------------------------------------------------------------
[2010-01-27 22:32:51] r at rcrowley dot org
Description:
------------
The specification outlined at http://json.org/ indicates that the
empty
string is a perfectly valid key in a JSON data structure. JSON
implementations in Python and Ruby agree. PHP appears to go out of its
way to handle the empty string as as key in a non-standard way.
Reproduce code:
---------------
$ php -r 'echo json_encode(json_decode("{\"\":\"foo\"}")),
"\n";'
{"_empty_":"foo"}
$
Expected result:
----------------
I expect to see exactly the same output from PHP as seen from Ruby and
Python:
$ ruby -rjson -e 'puts JSON.parse("{\"\":\"foo\"}").to_json'
{"":"foo"}
$ python -c 'import json;
print(json.dumps(json.loads("{\"\":\"foo\"}")))'
{"": "foo"}
$
Actual result:
--------------
$ php -r 'echo json_encode(json_decode("{\"\":\"foo\"}")),
"\n";'
{"_empty_":"foo"}
$
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50867&edit=1