#50867 [NEW]: json_encode can't handle empty string keys
| From: | r at rcrowley dot org | Date: | Wed, 27 Jan 2010 22:32:52 +0000 |
| Subject: | #50867 [NEW]: json_encode can't handle empty string keys | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-147009@lists.php.net to get a copy of this message | ||
From: r at rcrowley dot org
Operating system: Linux
PHP version: 5.3.1
PHP Bug Type: JSON related
Bug description: json_encode can't handle empty string keys
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 bug report at http://bugs.php.net/?id=50867&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=50867&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=50867&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=50867&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=50867&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=50867&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=50867&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=50867&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=50867&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=50867&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=50867&r=support
Expected behavior: http://bugs.php.net/fix.php?id=50867&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=50867&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=50867&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=50867&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50867&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50867&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=50867&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=50867&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=50867&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=50867&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=50867&r=mysqlcfg